Results 1 to 3 of 3

Thread: Seems that my emit doesn't emit the signal

  1. #1
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Seems that my emit doesn't emit the signal

    Hi,
    I'm making a GUI app with the wizard and wizardpages structure and I need to do some background heavy work in some cases so I’ve created the Worker class inheriting from QObject. Then, supposing I need to do some work in wp1 which is the first wizardpage, I have:

    in wp1.cpp constructor:
    Qt Code:
    1. thread = new QThread();
    2. worker = new Worker;
    3. worker->moveToThread(thread);
    4.  
    5. connect(this, SIGNAL(mysignal()),worker, SLOT(doWork()));
    To copy to clipboard, switch view to plain text mode 
    in worker.cpp:
    Qt Code:
    1. void Worker::doWork()
    2. {
    3. for (int i = 0; i <=200000; ++i)
    4. {
    5. qDebug() << i;
    6.  
    7. QEventLoop loop;
    8. QTimer::singleShot(1000, &loop, SLOT(quit())); // this should wait 1 sec like a sleep(1)
    9. loop.exec();
    10.  
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    in wp1.cpp I overwrite keypressed to emit the signal:
    Qt Code:
    1. void WP1::keyPressEvent(QKeyEvent *event) // definition
    2. {
    3. QWidget::keyPressEvent(event);
    4. switch(event->key())
    5. {
    6. case Qt::Key_1:
    7. qDebug() <<" before";
    8. emit(mysignal());
    9. qDebug() << "after";
    10. break;
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    My problem is that it prints ‘before’ and ‘after’ but seems that the signal is not emited so it never gets to the function worker::doWork()… Any idea of why?
    (I put the emit in keypressed just to control when I emit it to test if worker functions as I expect)

    Thank you!

  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: Seems that my emit doesn't emit the signal

    Did you start the thread? Did you run its event loop?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Seems that my emit doesn't emit the signal

    ohhh shit... yes that was... forgot to thread.start();

    thank you!

Similar Threads

  1. How to decide which SIGNAL to emit?
    By TheIndependentAquarius in forum Qt Programming
    Replies: 2
    Last Post: 22nd November 2011, 15:09
  2. Replies: 3
    Last Post: 7th April 2011, 11:09
  3. Emit signal from thread
    By sisco in forum Newbie
    Replies: 2
    Last Post: 26th November 2009, 13:32
  4. QUrlOperator doesn't emit finished signal
    By hayati in forum Qt Programming
    Replies: 16
    Last Post: 26th March 2007, 20:25
  5. emit a signal
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 27th February 2006, 11:14

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.