Results 1 to 2 of 2

Thread: Qt thread emit signal and the slot is fired later

  1. #1
    Join Date
    May 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Qt thread emit signal and the slot is fired later

    Hi all,

    I'm so fustrated because I'm trying to solve a problem with signals ans slot (C++ programming) and at the moment I don´t find the solution.

    This thing is the following, I did a SDK (MSVC 2010 C++) for capturing information from one camera. In this SDK there 2 windows threads (runniong through _beginthread), one thread read the information and another one decode this information when available and change the state of 1 shared variable.

    The program who use the SDK (QT visualizer), launch a QT thread to see the shared variable and when this variable change emit a signal in order to execute a slot.

    The code is :

    thread = new QThread();
    painter = new Painter();

    painter->moveToThread(thread);

    connect(painter, SIGNAL(workRequested()), thread, SLOT(start()));
    connect(thread, SIGNAL(started()), painter, SLOT(doWork()));
    connect(painter, SIGNAL(finished()), thread, SLOT(quit()), Qt:irectConnection);
    connect(painter, SIGNAL (MyNewSignal(int)), this, SLOT(On_Called_MyNewSignal(int)));


    And the behavior is not the expected, I received consecutives signals and execution of the slot not sincronyzed, for exemple :

    I can received something like that :

    emitmysignal(MyNewSignal)
    emitmysignal(MyNewSignal)
    emitmysignal(MyNewSignal)
    emitmysignal (MyNewSignal)
    On_Called_MyNewSignal
    On_Called_MyNewSignal
    On_Called_MyNewSignal
    On_Called_MyNewSignal
    emitmysignal(MyNewSignal)
    emitmysignal (MyNewSignal)
    On_Called_MyNewSignal
    emitmysignal (MyNewSignal)
    On_Called_MyNewSignal
    On_Called_MyNewSignal

    The execution of the slot is not immediately after the emitmysignal.

    What I'm doing wrong ?

    Anyone can help me ?

    Advanced thanks.

    Ferdinand

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt thread emit signal and the slot is fired later

    Please read about QObject::connect 5th parameter.

Similar Threads

  1. Emit signal from QThread to main thread!!!
    By sanujas in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 26th December 2013, 14:22
  2. Emit Signal and Slot question
    By kev.nam in forum Newbie
    Replies: 4
    Last Post: 3rd June 2011, 01:55
  3. Replies: 2
    Last Post: 3rd May 2011, 20:22
  4. emit signal from a slot?
    By ask8y@yahoo.com in forum Qt Programming
    Replies: 9
    Last Post: 11th June 2010, 20:18
  5. Emit signal from thread
    By sisco in forum Newbie
    Replies: 2
    Last Post: 26th November 2009, 13:32

Tags for this Thread

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.