Solved A simple connection error
-
Don't understand this either!
Here both QSplineBox and QSlider have one valueChanged/setValue respectively with one parameter of type int. Everything looks matched. Can't find the clue for the problem yet. -
@qcoderpro
Actually QSpinBox has two valueChanged signals:void valueChanged(int i)
void valueChanged(const QString &text) -
Where is the QString based one? I only found the int based: https://doc.qt.io/qt-5/qspinbox-members.html
-
@qcoderpro
It is in the Obsolete Members :) -
@Bonnie
Ow, found, thanks, solved. -
Another connection problem:
"dialogTest.h":
#ifndef DIALOGTEST_H #define DIALOGTEST_H #include <QDialog> class QPushButton; class QLineEdit; class dialogTest : public QDialog { Q_OBJECT public: dialogTest(QWidget *parent = nullptr); ~dialogTest(); private: QPushButton* button; QLineEdit* lineEdit; }; #endif // DIALOGTEST_H
"dialogTest.cpp":
#include "dialogtest.h" #include <QPushButton> #include <QLineEdit> #include <QHBoxLayout> #include <QVBoxLayout> dialogTest::dialogTest(QWidget *parent) : QDialog(parent) { button = new QPushButton(tr("Close")); lineEdit = new QLineEdit; QHBoxLayout* hLayout = new QHBoxLayout; hLayout->addWidget(lineEdit); hLayout->addWidget(button); setLayout(hLayout); connect(button, &QPushButton::clicked, &QDialog, &QDialog::close); } dialogTest::~dialogTest() { delete button; delete lineEdit; }
I get this error: error: expected primary-expression before ',' token
connect(button, &QPushButton::clicked, &dialogTest, &dialogTest::close)Even when I use this instead:
connect(button, &QPushButton::clicked, &dialogTest, &dialogTest::close);
I get the same error: error: expected primary-expression before ',' token
connect(button, &QPushButton::clicked, &dialogTest, &dialogTest::close); -
@qcoderpro
The third parameter should be a pointer.
So "& + ClassName" is not a valid expression.
You should use "this". -
So an address is not accepted and should it exactly be a pointer!? Why?
And that this you used is actually a pointer to the object we've created in main.cpp, right?
-
@qcoderpro
An address to an QObject object is acceptable. But I don't think "& + ClassName" is an address. It is not a valid expression at all.
And I haven't seen your main.cpp with a dialogTest, so I'm not sure.
But isn't "this" very basic in C++ class knowledge? -
Yeah, a pointer varies from an address.
This is my main.cpp:
#include "dialogtest.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); dialogTest w; w.show(); return a.exec(); }
So the "this" you used is the pointer to the object, here "w", as the top-level widget of the project. Is it right?
-
@qcoderpro
Yeah, using "this" inside dialogTest equals "&w".