Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QObject::connect not working - Signal not found with function syntax

Tags:

c++

qt

I am trying to create a very basic dialog with Qt:

QDialog *inputDialog = new QDialog(g.ParentWidget);
QVBoxLayout *layout = new QVBoxLayout(inputDialog);
inputDialog->setWindowTitle(to_qstring(p_strTitle));
inputDialog->setLayout(layout);

QDialogButtonBox *buttonBox = new QDialogButtonBox(
  QDialogButtonBox::Cancel | QDialogButtonBox::Ok, inputDialog);
layout->addWidget(buttonBox);

QObject::connect(buttonBox, &QDialogButtonBox::accepted, inputDialog, &QDialog::accept);
QObject::connect(buttonBox, &QDialogButtonBox::rejected, inputDialog, &QDialog::reject);

inputDialog->setModal(true);
if (inputDialog->exec() != QDialog::Accepted) {
  return gcnew array<int>(0);
}

Where g.ParentWidget is a QWidget from elsewhere. This code is in a static method, outside of a class.

When I run this, I get:

QObject::connect: signal not fount in QDialogButtonBox

I tried looking for similar issues but I only found answers for trivial issues with old Qt syntax, or when signals: was missing, which is not the case there.

Any idea what I am doing wrong? What could be causing this?


This code is called within a C++/CLR project, in a piece of codes that gets called from C#, but I have no issue with similar stuff using QMessageBox.

like image 960
Holt Avatar asked Mar 15 '26 14:03

Holt


1 Answers

since you did not specify the compiler, OS, and I also encountered such an error, I advise you to switch to the old syntax,

QObject::connect(buttonBox, &QDialogButtonBox::accepted, inputDialog, &QDialog::accept);
QObject::connect(buttonBox, &QDialogButtonBox::rejected, inputDialog, &QDialog::reject);

change to

QObject::connect(buttonBox, SIGNAL(accepted()), inputDialog, SLOT(accept()));
QObject::connect(buttonBox, SIGNAL(rejected()), inputDialog, SLOT(reject()));

such a permutation solved my problem

like image 153
Vahagn Avagyan Avatar answered Mar 18 '26 04:03

Vahagn Avagyan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!