Unsolved Direct connect a built-in signal from one class to a slot on another class
-
@JonB said in Direct connect a built-in signal from one class to a slot on another class:
@Habibie
You say this works:connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(indexChanged(int)));
and it's inside
DialogOne::DialogOne()
.The above uses the old string SIGNAL/SIGNAL connection style.
Then you say you changed to
connect(comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index){
still inside
DialogOne::DialogOne()
.The compiler says
../src/dialogone.cpp:12:13: error: ‘comboBox’ was not declared in this scope
Why have you changed from
ui->comboBox
tocomboBox
?The above uses a new functional connection with lambda.
BTW, with an old style string SIGNAL/SIGNAL connection, if I change from this
connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(indexChanged(int)));
to this
connect(comboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(indexChanged(int)));
the compilation spits out the following error messages.
g++ -c -pipe -g -std=gnu++11 -Wall -Wextra -D_REENTRANT -fPIC -DGIT_VERSION=\"\" -DGIT_HASH=\"febc5d8c3a77a4a9039601f638b0ce220c3b3189\" -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../../SignalsAndSlots-01 -I. -I../include -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -I/usr/include/x86_64-linux-gnu/qt5/QtGui -I/usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I. -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -o dialogone.o ../src/dialogone.cpp ../src/dialogone.cpp: In constructor ‘DialogOne::DialogOne(QWidget*)’: ../src/dialogone.cpp:12:13: error: ‘comboBox’ was not declared in this scope; did you mean ‘QComboBox’? 12 | connect(comboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(indexChanged(int))); | ^~~~~~~~ | QComboBox make: *** [Makefile:566: dialogone.o] Error 1
-
Hi,
That's exactly the point of @JonB, there's no reason to remove the ui-> from your code.
-
@SGaist said in Direct connect a built-in signal from one class to a slot on another class:
Hi,
That's exactly the point of @JonB, there's no reason to remove the ui-> from your code.
Got it and thank you for pointing it out.