C++ + Gtkmm + Thread + new window
- From: Mateusz Szygenda <morfeuszpl o2 pl>
- To: gtk-app-devel-list gnome org
- Subject: C++ + Gtkmm + Thread + new window
- Date: Tue, 27 Feb 2007 19:57:27 +0100
Hello,
This is my first post on this list, but not last :). I would be
thankful, if you help me in solving my problem.
I use, gtkmm-2.4 and i'm writing a simple InstantMessager. I created a
simple GUI using glademm and everything works fine, but i wanted to open
conversation window when someone send message, so i created method which
check for new messages and if there is some message it create new
"conversation window". I run this method in new thread...and then the
problem started. When method call "ConversationWindow" constructor, i
receive many errors from GTK. I think method is okay(if i call this
method without creating a new thread everything works fine, but app
hangs up :) ).
Console(When new message arrived, and Conversation() is called.:
(linqq:7237): Gtk-CRITICAL **: gtk_text_attributes_ref: assertion
`values != NULL' failed
(linqq:7237): Gtk-CRITICAL **: gtk_text_attributes_ref: assertion
`values != NULL' failed
(linqq:7237): Pango-CRITICAL **: pango_layout_new: assertion `context !=
NULL' failed
Debuger:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1223346496 (LWP 7244)]
0xb7b62e89 in gtk_text_layout_validate () from /usr/lib/libgtk-x11-2.0.so.0
The code is:
ConversationManager ( it's class which manage conversation windows(If
some window is already created it activate it. or create new)
/**
That create new Window(This works fine, when i run it from main thread.
newAccount - is from network code of my IM.
*/
void ConversationManager::newConversation(unsigned int newNumber, char
*message, Account *newAccount)
{
int size = conversations.size();
if(size > 0)
{
for(int i = 0; i < size; i++)
{
if(conversations[i]->getNumber() == newNumber)// This works
fine, even in new thread(If i create newWindow from main thread and
someone send message this code works fine in new thread)
{
conversations[i]->show();
conversations[i]->addMessage(message);
return;
}
}
}
Conversation *newConversation = new Conversation(); // Conversation
is class generated by glademm(conversation window class). That generate
error :/
newConversation->setAccount(newAccount); //-----------------------------
newConversation->setNumber(newNumber); //nothing important
newConversation->addMessage(message);// ------------------
newConversation->show();
conversations.push_back(newConversation); // It's a array of
pointers for conversation windows
user = newAccount; //nothing important
}
/**
I call this method in new thread.
*/
void ConversationManager::waitForMessages()
{
Message temp; // From network part of IM.
if(user != 0 && !waiting)
{
waiting = true;
for(;;)
{
if(user->getMessageQueueLength() > 0) // If is there any
messages
{
temp = user->getMessageFromQueue();
newConversation(temp.getSender(),temp.getMessage(),this->user); //
Create new window!
}
}
}
}
I think Conversation and Conversation_glade() is good beacause it's
generated by glademm. Now my question is. How to create window in new
thread? Please help me.
PS: Sorry for my english.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]