PDA

View Full Version : Threads and SIGNAL



gorka_sm
28th April 2010, 15:08
Hello , I am developing a Qt application which has a MythDialogBox in which a Button is added. When this button is clicked it is supposed that a SIGNAL is executed and the application is closed.
The MythDialogBox is created in a pthread . The main problem that I have is that the function called by the SIGNAL is never executed.

So First question : Do you know any method or tutorial for executing SIGNALS in pthreads ?




Here I have the code I have developed :

---- Main Class ----


pthread_t base_thread;
int valor = pthread_create(&base_thread, NULL, run_base_thread, NULL);


static void *run_base_tread(void *data)
{

while true{

gContext-> SetMainWindow(NULL);
bool frontendOnly = gContext->IsFrontendOnly();
gContext->SetMainWindow(MythMainWindow::getMainWindow());

MythScreenStack *ss = GetMythMainWindow() ->GetStack("popup stack");

MythDialogBox *dlg = new MythDialogBox(tr("Exit Mythtv"),ss,"exit prompt");
dlg ->AddButton(tr("Yes"),SLOT(quit));

}

quit{
qapp->exit()
}
}

The main problem is that the method quit is never executed

squidge
28th April 2010, 17:45
To use inter-thread signals, you must use an event loop. Either the main threads loop or the thread-specific event loop.

Sub-class QThread to get this functionality.

gorka_sm
28th April 2010, 22:02
Do you have a example of code using the QTthread ?
Do you know if it is possible to do that using pthread subclass?
Thanks
Gorka

borisbn
29th April 2010, 04:17
1. read this about threading in Qt (doc.qt.nokia.com/4.6/threads.html)
2. Slot should be a member of class, derived from QObject
3. See output window in your IDE or in console. Qt writes all errors, ocured while using signal/slots there