Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » ChatClient with Ultimate++
ChatClient with Ultimate++ [message #14666] Thu, 06 March 2008 18:06 Go to next message
chochmah is currently offline  chochmah
Messages: 5
Registered: March 2008
Promising Member
Hi Forum,
My Problem is this:
I have written a chatclient using a chatlibrary that provides a function named chatout(char *text). Everytime the clint receives a new chatline chatout() is called;

My Question:
How can I make a change to the richtextview-widget from outside the Withj2Layout<TopWindow> class that the richtextview-widget blongs to? Just calling the widget.SetQTF(CHATTEXT); results in a crash.
Doing it with a callback from the TopWindow works, but callbacks are only called when something within the TopWindow happens and not when a string extern to the function is changed.
(I just want to change the displayed text in the windget when chatout() receives something)

I hope this is understable.

Thanks Alot for your time and help

chochmah
Re: ChatClient with Ultimate++ [message #14667 is a reply to message #14666] Thu, 06 March 2008 20:54 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
chochmah wrote on Thu, 06 March 2008 12:06

Hi Forum,
My Problem is this:
I have written a chatclient using a chatlibrary that provides a function named chatout(char *text). Everytime the clint receives a new chatline chatout() is called;

My Question:
How can I make a change to the richtextview-widget from outside the Withj2Layout<TopWindow> class that the richtextview-widget blongs to? Just calling the widget.SetQTF(CHATTEXT); results in a crash.



It should not. Anyway, hard to say if we do not know details. Testcase suggested.

Mirek
Re: ChatClient with Ultimate++ [message #14668 is a reply to message #14666] Thu, 06 March 2008 21:39 Go to previous messageGo to next message
chochmah is currently offline  chochmah
Messages: 5
Registered: March 2008
Promising Member
///layout

LAYOUT(j2Layout, 624, 436)
ITEM(LineEdit, a, LeftPosZ(4, 564).TopPosZ(412, 20))
ITEM(RichTextView, e, LeftPosZ(0, 624).TopPosZ(0, 408))
END_LAYOUT

///main

class j2 : public Withj2Layout<TopWindow> {
public:
typedef j2 CLASSNAME;
j2();
};

j2 HG;
String qtfx;

j2::j2() {
CtrlLayout(*this, "Joachim 0.1");
SetLanguage( LNG_('D','E','D','E') );
SetDefaultCharset(CHARSET_UTF8);
}

void textin_cb(int x,String farbe,String Sender,String text) {
qtfx<<"\1"<<Sender<<":"<<text<<"\1]&";
HG.e.SetQTF(qtfx);
HG.e.ScrollEnd();
}


GUI_APP_MAIN
{
readinifile();
int ids = 1;
pthread_t threads;
pfi = &ParseChatLine;
pthread_create (&threads, NULL, readchat, &ids);
HG.Run();
}


Thanks for the Reply, I hope this helps. Calling textin_cb result in an heap or memory error when:
-The scrollbar is moved while textin_cb is called
-More then one page of text in the widget
(also happens without HG.e.ScrollEnd()Wink


Thank you
Re: ChatClient with Ultimate++ [message #14671 is a reply to message #14668] Thu, 06 March 2008 22:02 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
chochmah wrote on Thu, 06 March 2008 15:39

///layout

LAYOUT(j2Layout, 624, 436)
ITEM(LineEdit, a, LeftPosZ(4, 564).TopPosZ(412, 20))
ITEM(RichTextView, e, LeftPosZ(0, 624).TopPosZ(0, 408))
END_LAYOUT

///main

class j2 : public Withj2Layout<TopWindow> {
public:
typedef j2 CLASSNAME;
j2();
};

j2 HG;
String qtfx;

j2::j2() {
CtrlLayout(*this, "Joachim 0.1");
SetLanguage( LNG_('D','E','D','E') );
SetDefaultCharset(CHARSET_UTF8);
}

void textin_cb(int x,String farbe,String Sender,String text) {
qtfx<<"\1"<<Sender<<":"<<text<<"\1]&";
HG.e.SetQTF(qtfx);
HG.e.ScrollEnd();
}


GUI_APP_MAIN
{
readinifile();
int ids = 1;
pthread_t threads;
pfi = &ParseChatLine;
pthread_create (&threads, NULL, readchat, &ids);
HG.Run();
}


Thanks for the Reply, I hope this helps. Calling textin_cb result in an heap or memory error when:
-The scrollbar is moved while textin_cb is called
-More then one page of text in the widget
(also happens without HG.e.ScrollEnd()Wink


Thank you


Still too little info. I do not even see when textin_cb is called....

A proper testcase is zipped package to demonstrate the rpoblem that compiles, most preferably on both Win32 and linux.


Anyway:

If you are using threads, you should use U++ threads, otherwise you will have memory leaks.

GUI can run in the main thread only.

Mirek
Re: ChatClient with Ultimate++ [message #14672 is a reply to message #14671] Thu, 06 March 2008 22:20 Go to previous messageGo to next message
chochmah is currently offline  chochmah
Messages: 5
Registered: March 2008
Promising Member
hi,

testcase: testcase

unfortunatly that works only with windows.

Thanks

chochmah
Re: ChatClient with Ultimate++ [message #14679 is a reply to message #14672] Fri, 07 March 2008 17:46 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, for starters... As I said, only main thread can do GUI. You are calling the textin_cb from non-main thread and calling SetQTF there. That cannot work. Use Post of callback there.

Also, you should not use global variables for widgets.

Mirek
Re: ChatClient with Ultimate++ [message #14680 is a reply to message #14679] Sat, 08 March 2008 03:37 Go to previous message
chochmah is currently offline  chochmah
Messages: 5
Registered: March 2008
Promising Member
I did as you suggested and used a postcallback, now it works perfectly.

thank you very much!
Previous Topic: [BUG] Ctrl::AlignRight
Next Topic: what is the largest Array size please? ("out of memory" error)
Goto Forum:
  


Current Time: Mon Apr 29 03:26:15 CEST 2024

Total time taken to generate the page: 0.03357 seconds