Unsolved Problem in Connecting ctkDoubleSpinBox
-
- I am trying to add an action listener to
ctkDoubleSpinBox
ofqMRMLSliceControllerWidget
and changeQLabel
value inqMRMLSliceWidget
. - I am able to access
ctkDoubleSpinBox
insideqMRMLSliceWidget
and add a connection as shown below.
connect(this->SliceController->spinBox, SIGNAL(valueChanged(double)), this, SLOT(updateLabel())); void qMRMLSliceWidget::updateLabel() { Q_D(qMRMLSliceWidget); d->SpinBoxVal->setText(d->SliceController->spinBox->cleanText()); }
- Error:
'QMetaObject::Connection QObject::connect(const QObject *,const char *,const QObject *,const char *,Qt::ConnectionType)': cannot convert argument 1 from 'ctkDoubleSpinBox *' to 'const QObject *'
- How can I add a connection to
ctkDoubleSpinBox
?
- I am trying to add an action listener to
-
@Meera-Hadid said in Problem in Connecting ctkDoubleSpinBox:
ctkDoubleSpinBox
Is it derived from QObject?
-
Yes.
ctkDoubleSpinBox
class:class CTK_WIDGETS_EXPORT ctkDoubleSpinBox : public QWidget
-
@Meera-Hadid Does it also have Q_OBJECT macro? Like
class MyClass : public QObject { Q_OBJECT
-
Yes.
class CTK_WIDGETS_EXPORT ctkDoubleSpinBox : public QWidget { Q_OBJECT Q_ENUMS(SetMode) Q_FLAGS(DecimalsOption DecimalsOptions) Q_ENUMS(SizeHintPolicy) Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) Q_PROPERTY(bool frame READ hasFrame WRITE setFrame) Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) Q_PROPERTY(QString prefix READ prefix WRITE setPrefix) Q_PROPERTY(QString suffix READ suffix WRITE setSuffix) Q_PROPERTY(QString cleanText READ cleanText) ....
-
@Meera-Hadid said in Problem in Connecting ctkDoubleSpinBox:
ctkDoubleSpinBox
Did you also include the header for this class where you do the connect?
-
Yes I Did.
#include <ctkDoubleSpinBox.h>
-
@Meera-Hadid Try to do the connect using new connect syntax https://doc.qt.io/qt-5/signalsandslots.html
-
I think Christian meant, did you add the header ctkDoubleSpinBox.h to the HEADERS variable in your PRO file?
Did you run qmake after doing that?
Have you tried a clean rebuild of everything? -
- do you mean this syntax?
Counter a, b; QObject::connect(&a, &Counter::valueChanged, &b, &Counter::setValue);
- I am getting a syntax error when I use this:
this->SliceController->&spinBox
-
@Meera-Hadid said in Problem in Connecting ctkDoubleSpinBox:
I am getting a syntax error when I use this:
this->SliceController->&spinBox
This is not legal C++. It should be:
&this->SliceController->spinBox
Whether you want the
&
depends on whetherspinbox
is already a pointer or not (I think yours is a pointer, in which case you would not want it?) -
@JonB said in Problem in Connecting ctkDoubleSpinBox:
&this->SliceController->spinBox
But according to the error message
cannot convert argument 1 from 'ctkDoubleSpinBox *' to 'const QObject *
It's already a pointer so the
&
is wrong.
I still think the header for this class is not included where the connect is done so the compiler doesn't know that ctkDoubleSpinBox is derived from QObject. -
- I did include
#include <ctkDoubleSpinBox.h>
- I did include
-
@Meera-Hadid Fix your connect as suggested by @JonB and try again
-
-
@Meera-Hadid said in Problem in Connecting ctkDoubleSpinBox:
Yes when I tried without using & it was raising an error that cannot convert from 'ctkDoubleSpinBox *' to 'const QObject *'
The issue is not getting pointer the issue is it cannot convert from 'ctkDoubleSpinBox *' to 'const QObject *'
Inserting a
&
randomly will not help. The message already tells that pointer-ness is not the issue. -
@Meera-Hadid said in Problem in Connecting ctkDoubleSpinBox:
The issue is not getting pointer the issue is it cannot convert from 'ctkDoubleSpinBox *' to 'const QObject *'
Do you mean you get same error message if you use new connect syntax?
-
@Meera-Hadid
Please do the following:- First, delete all the files from the build output directory. Do a fresh
qmake
followed by a build. Does the error still occur? - From the line number in the error message, are you quite sure it is on the
connect()
statement you have shown, and not some other? - I believe I already advised this before in answer to the same problem from you in another thread: on the line above the
connect()
put in
const QObject *temp = this->SliceController->spinBox;
Does that error (show message)?
- First, delete all the files from the build output directory. Do a fresh
-
const QObject *temp = this->SliceController->spinBox;
this works- But the signal
SIGNAL(valueChanged(double))
doesn't get activated (QLabel
value doesn't change). Is it becausetemp
is returingnullptr
?
-
Is it because temp is returing nullptr?
Pardon? Are you saying
this->SliceController->spinBox == nullptr
at the time you execute theconnect()
statement?Separately, put a
qDebug()
statement as the first thing in yourvoid qMRMLSliceWidget::updateLabel()
.