PDA

View Full Version : Connect - "cannot convert parameter1 from QSlider * to const QObject * "



gebbissimo
31st August 2012, 19:13
Hi everyone,

I'm new to this forum as to C++ and now Qt. Currently I'm studying this tutorial http://doc.qt.nokia.com/4.4/tutorials-tutorial-t8.html . I hope that some of you are familiar with it?

CODE IN TUTORIAL
~~~~~~~~~~~~~~~~~~~~~~~
In the tutorial they do several connects. I believe those are relevant atm:

In lcdrange.cpp:


connect(slider, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));

In main.cpp


LCDRange *angle = new LCDRange;
connect(angle, SIGNAL(valueChanged(int)), cannonField, SLOT(setAngle(int)));



So, they connect slider.valueChanged(int) with the slot cannonField.setAngle(int) "via" the signal angle.valueChanged(int).


PROBLEM
~~~~~~~~~~~~~~~~~~~~~~~~~~~
I tried to connect them directly. In main.cpp I added the line


connect(angle->slider, SIGNAL(valueChanged(int)), cannonField, SLOT(setAngle(int)));


(I also turned the QSlider * slider public in lcdrange.h)

But then the build problem occurs "cannot convert parameter 1 from 'QSlider *' to 'const QObject *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast". I don't really understand the problem. In my view, they were connected already before, just indirect.

I would be grateful if anybody could explain it to me, thanks!

norobro
31st August 2012, 22:33
Sometimes compiler error messages can be rather cryptic. Add the following to your main.cpp:

#include <QSlider>
The Clang (http://llvm.org/) compiler spits out a more understandable error:

candidate function not viable: cannot convert argument of incomplete type 'QSlider *' to 'const QObject *'

frankiefrank
24th December 2015, 13:33
This helped me so much! Thank you!