How to quit an eventLoop connect to a signal containing arguments?
-
I'm getting this error in the
evenLoop.quit()
line:E1086 the object has type qualifiers that are not compatible with the member function "QEventLoop::quit"
QEventLoop eventLoop; connect(msgBox, &MsgBox::signalCancel, &eventLoop, [=] (QString text) { qDebug() << text; eventLoop.quit(); }); eventLoop.exec();
What the proper way to quit the loop in this case?
-
I'm getting this error in the
evenLoop.quit()
line:E1086 the object has type qualifiers that are not compatible with the member function "QEventLoop::quit"
QEventLoop eventLoop; connect(msgBox, &MsgBox::signalCancel, &eventLoop, [=] (QString text) { qDebug() << text; eventLoop.quit(); }); eventLoop.exec();
What the proper way to quit the loop in this case?
@Ylvy said in How to quit an eventLoop connect to a signal containing arguments?:
eventLoop.quit();
I can't test, but don't you mean
this->quit()
or justquit()
since&eventLoop
is thethis
for the slot lambda?If not that, does it make any difference here if you use
[&]
instead of[=]
? -
I'm getting this error in the
evenLoop.quit()
line:E1086 the object has type qualifiers that are not compatible with the member function "QEventLoop::quit"
QEventLoop eventLoop; connect(msgBox, &MsgBox::signalCancel, &eventLoop, [=] (QString text) { qDebug() << text; eventLoop.quit(); }); eventLoop.exec();
What the proper way to quit the loop in this case?
Apart from the fact that I don't see a need for a local eventloop - how is you signalCancel defined?
-
Apart from the fact that I don't see a need for a local eventloop - how is you signalCancel defined?
@Christian-Ehrlicher
The event loop is to wait the click in one of the MsgBox buttons.QT_BEGIN_NAMESPACE namespace Ui { class MsgBox; }; QT_END_NAMESPACE class MsgBox : public QWidget { Q_OBJECT public: Ui::MsgBox* m_ui; MsgBox(QWidget* parent) void cancel(); signals: void signalCancel(QString text); }; MsgBox::MsgBox(QWidget* parent) : QWidget(parent) , m_ui(new Ui::MsgBox()) { m_ui->setupUi(this); connect(m_ui->cancel, &QPushButton::clicked, this, &MsgBox::cancel); } void MsgBox::cancel() { emit signalCancel("test 123"); }
-
I'm getting this error in the
evenLoop.quit()
line:E1086 the object has type qualifiers that are not compatible with the member function "QEventLoop::quit"
QEventLoop eventLoop; connect(msgBox, &MsgBox::signalCancel, &eventLoop, [=] (QString text) { qDebug() << text; eventLoop.quit(); }); eventLoop.exec();
What the proper way to quit the loop in this case?
@Ylvy said in How to quit an eventLoop connect to a signal containing arguments?:
eventLoop.quit();
I can't test, but don't you mean
this->quit()
or justquit()
since&eventLoop
is thethis
for the slot lambda?If not that, does it make any difference here if you use
[&]
instead of[=]
? -
@Ylvy said in How to quit an eventLoop connect to a signal containing arguments?:
eventLoop.quit();
I can't test, but don't you mean
this->quit()
or justquit()
since&eventLoop
is thethis
for the slot lambda?If not that, does it make any difference here if you use
[&]
instead of[=]
?@JonB said in How to quit an eventLoop connect to a signal containing arguments?:
If not that, does it make any difference here if you use [&] instead of [=]?
You're correct - QEventLoop is an QObject and therefore can't be copied.
-
@Ylvy said in How to quit an eventLoop connect to a signal containing arguments?:
eventLoop.quit();
I can't test, but don't you mean
this->quit()
or justquit()
since&eventLoop
is thethis
for the slot lambda?If not that, does it make any difference here if you use
[&]
instead of[=]
? -
-
@Christian-Ehrlicher
The event loop is to wait the click in one of the MsgBox buttons.QT_BEGIN_NAMESPACE namespace Ui { class MsgBox; }; QT_END_NAMESPACE class MsgBox : public QWidget { Q_OBJECT public: Ui::MsgBox* m_ui; MsgBox(QWidget* parent) void cancel(); signals: void signalCancel(QString text); }; MsgBox::MsgBox(QWidget* parent) : QWidget(parent) , m_ui(new Ui::MsgBox()) { m_ui->setupUi(this); connect(m_ui->cancel, &QPushButton::clicked, this, &MsgBox::cancel); } void MsgBox::cancel() { emit signalCancel("test 123"); }
@Ylvy said in How to quit an eventLoop connect to a signal containing arguments?:
m_ui
this is leaking.
Still don't understand why you are blocking the execution with a local eventloop.
-
@Ylvy said in How to quit an eventLoop connect to a signal containing arguments?:
m_ui
this is leaking.
Still don't understand why you are blocking the execution with a local eventloop.
@Christian-Ehrlicher what is leaking? the ui i destructed in the class destructor?
Still don't understand why you are blocking the execution with a local eventloop.
The execution is blocked until one of the buttons of the class is clicked, how else i would block it until the click?
-
@Christian-Ehrlicher what is leaking? the ui i destructed in the class destructor?
Still don't understand why you are blocking the execution with a local eventloop.
The execution is blocked until one of the buttons of the class is clicked, how else i would block it until the click?