Results 1 to 2 of 2

Thread: emit signal should wait for slot response

  1. #1
    Join Date
    Aug 2013
    Location
    India
    Posts
    44
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default emit signal should wait for slot response

    Hello Everyone,

    I have a thread function in which i am emitting a SIGNAL with passing pointer as argument.
    Value in argument will be fill in SLOT function and i would like to check the value before execution of next step.

    //MainWindow Constructor
    MainWindow::MainWindow
    (QWidget * parent
    ): QMainWindow()

    {
    connect(this, SIGNAL(sigPdfOpen(int*)), this, SLOT(openPDF(int*)); // connect for emit sigPdfOpen
    }
    // this is a cleaning function
    void MainWindow::cleaning()
    {
    if (Scheduler->addJob(tasktype::cleaning))
    {
    qDebug() << "Cleaning job added in the queue." << endl;
    }
    }

    // when job will be sucessfully added this thread function will be call
    bool MainWindow::thread_cleaning()
    {
    qDebug() << "in thread_cleaning" << endl;
    return startRequest();
    }

    // this API will be call from thread_cleaning function
    bool MainWindow::startRequest()
    {
    int retpdf = 5;
    emit sigPdfOpen(&retpdf); //passing retPDF as pointer in signal

    // Below code should perform after ger retpdf value but it is not waiting for slot execution result

    if (retpdf == 0)
    {
    qDebug() << "confirm button click";
    return true;
    }
    else if (retpdf == 1)
    {
    qDebug() << "Redo button click";
    return false;
    }
    }

    // SLOT function for
    void MainWindow:penPDF(int* retpdf)
    {
    dialog = new CustomPDFDialog();

    if (dialog->exec() == QDialog::Accepted)
    {
    *retpdf = 0;
    }
    else
    {
    *retpdf = 1;
    }
    }

    but after emit sigPdfOpen(&retpdf) code is not waiting for slot execution result basically slot is executing after 5 seconds.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: emit signal should wait for slot response

    When you make the connect() call, try passing Qt::BlockingQueuedConnection as the connection type (last argument).

    Please use CODE tags when posting source code. See my signature block below.
    Last edited by d_stranz; 13th April 2020 at 16:56.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Qt thread emit signal and the slot is fired later
    By dragonprog in forum Qt Programming
    Replies: 1
    Last Post: 14th March 2017, 14:00
  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. Replies: 1
    Last Post: 12th October 2010, 22:38
  5. emit signal from a slot?
    By ask8y@yahoo.com in forum Qt Programming
    Replies: 9
    Last Post: 11th June 2010, 20:18

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.