Results 1 to 5 of 5

Thread: Connecting signals & slots across different threads

  1. #1
    Join Date
    Apr 2006
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Connecting signals & slots across different threads

    I have created one GUI application & one thread MyThread.
    I am trying to connect signal of thread with slot of application & vice versa.
    From GUI, I am calling signal connecting to Slot A of MyThread.
    From the slot A of MyThread, I am emitting signal that connects slot B of application.
    But my application is not running.
    Pls help.

    Here is ths code for connection -
    CFacade *pFacade = CFacade::getUniqueInstance();
    CRouterThread *pRtrThread = new CRouterThread(pFacade);

    connect(CFacadeHandler::getUniqueInstance(pFacade->m_uiMainWindow), SIGNAL(readRouterInputs()), pRtrThread, SLOT(processRouterInputs()), Qt::QueuedConnection);

    connect(CFacadeHandler::getUniqueInstance(pFacade->m_uiMainWindow), SIGNAL(startRouting()), pRtrThread, SLOT(runRouter()), Qt::QueuedConnection);

    connect(pRtrThread, SIGNAL(displayInfo(QString)), pFacade->m_uiMainWindow.outputPane, SLOT(append(QString)), Qt::QueuedConnection);

    connect(pRtrThread, SIGNAL(taskOver()), CFacadeHandler::getUniqueInstance(pFacade->m_uiMainWindow), SLOT(changeCursorShape()), Qt::QueuedConnection);

    pRtrThread->start();

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Connecting signals & slots across different threads

    What do you mean by "application is not running"?

  3. #3
    Join Date
    Apr 2006
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Connecting signals & slots across different threads

    Quote Originally Posted by wysota
    What do you mean by "application is not running"?
    I meant that I was not able to execute the application.
    That problem is resolved, but I am facing one more problem -
    I am trying to create 2 threads from GUI application - CRouterThread & CChipViewerThread.
    CRouterThread is working fine, but I am not able to instantiate another GUI application on CChipViewerThread.

    Pls find attached the files for the same.
    PSSController is tha main class where I am creating thread & corresponding connections.
    CChipViewerThread is the thread class.

    Regards
    Attached Files Attached Files

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Connecting signals & slots across different threads

    Quote Originally Posted by jyoti kumar
    CRouterThread is working fine, but I am not able to instantiate another GUI application on CChipViewerThread.
    There can be only one GUI thread in Qt application.

    http://doc.trolltech.com/4.1/threads.html

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Connecting signals & slots across different threads

    See: Thread support in Qt

    Although QObject is reentrant, the GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread. As noted earlier, QCoreApplication::exec() must also be called from that thread.

    In practice, the impossibility of using GUI classes in other threads than the main thread can easily be worked around by putting time-consuming operations in a separate worker thread and displaying the results on screen in the main thread when the worker thread is finished. This is the approach used for implementing the Mandelbrot and the Blocking Fortune Client example.
    J-P Nurmi

Similar Threads

  1. Connecting signals and slots help pls
    By bod in forum Qt Programming
    Replies: 9
    Last Post: 1st July 2008, 15:01
  2. Signals and Slots
    By 83.manish in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 10:31
  3. Problem with SpinBox signals and slots
    By ramstormrage in forum Newbie
    Replies: 4
    Last Post: 2nd May 2008, 01:45
  4. Signals and Slots Across Threads
    By themusicalguy in forum Qt Programming
    Replies: 1
    Last Post: 26th October 2007, 11:16
  5. [QT4] threads, signals, and slots, please help.
    By ucntcme in forum Qt Programming
    Replies: 12
    Last Post: 25th January 2006, 14:23

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.