Results 1 to 4 of 4

Thread: Threads and SIGNAL

  1. #1
    Join Date
    Apr 2010
    Posts
    13
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Threads and SIGNAL

    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

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Threads and SIGNAL

    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.

  3. #3
    Join Date
    Apr 2010
    Posts
    13
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: Threads and SIGNAL

    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

  4. #4
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Threads and SIGNAL

    1. read this about threading in Qt
    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

Similar Threads

  1. signal mapping on pushbutton signal clicked
    By wagmare in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2009, 07:54
  2. Signal-Signal Connections Between Threads
    By PhilippB in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2008, 18:27
  3. signal and slot across threads having event loop
    By travis in forum Qt Programming
    Replies: 6
    Last Post: 5th November 2007, 23:56
  4. Signal / Slot with specific argument and threads
    By tpf80 in forum Qt Programming
    Replies: 3
    Last Post: 14th September 2007, 23:43
  5. signal/slots across threads in Qt4
    By Ambiorix in forum Qt Programming
    Replies: 7
    Last Post: 31st July 2006, 08:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.