PDA

View Full Version : emit signal should wait for slot response



prabhatjha
13th April 2020, 11:42
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::openPDF(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.

d_stranz
13th April 2020, 16:26
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.