PDA

View Full Version : Compiler error when calling QObject::connect. What am I missing?



themanwiththequestion
2nd February 2010, 11:55
I have encountered a strange compiler error when trying to connect a QGraphicsView's QScrollBar to a slot in my own class.
The code is as follows (simplified):



MyClass::MyClass(QWidget * parent, Qt::WindowFlags f): QDialog(parent, f)
{
_widget.setupUi(this);

_imageScene = new QGraphicsScene;

_widget.graphicsView->setScene(_imageScene);

//This works
connect(_widget.imageListView->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(currentImageChanged(const QModelIndex&)));

//These two are causing the compiler errors
connect(_widget.graphicsView->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(updateVisibleRect()));
connect(_widget.graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(updateVisibleRect()));
}


I didn't forget the Q_OBJECT declaration and the updateVisibleRect() is declared as a slot just like the other slots I have in the class.
There are a couple of other connects in the constructor I omitted. But they are working just fine. Only if I try to connect the QGraphicsView's scroll bars to my slots, there is a compiler error:



src/MyClass.cpp:58: error: no matching function for call to `MyClass::connect(QScrollBar*, const char*, MyClass* const, const char*)'

d:/Programme/Qt/2009.04/qt/include/QtCore/../../src/corelib/kernel/qobject.h:202: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)

d:/Programme/Qt/2009.04/qt/include/QtCore/../../src/corelib/kernel/qobject.h:308: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const

src/MyClass.cpp:59: error: no matching function for call to `MyClass::connect(QScrollBar*, const char*, FATThresholdDialog* const, const char*)'

d:/Programme/Qt/2009.04/qt/include/QtCore/../../src/corelib/kernel/qobject.h:202: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)

d:/Programme/Qt/2009.04/qt/include/QtCore/../../src/corelib/kernel/qobject.h:308: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const



It seems to me that there is a problem with the type returned by QGraphicsView::horizontalScrollBar().
Strangely, connecting the selectionModel of a QListView I'm also using to one of my slots works just fine.

Is there something I am missing? Any ideas on what causes the error?

Thanks in advance

Someone With A Question

high_flyer
2nd February 2010, 13:00
Post Deleted

rexi
2nd February 2010, 13:14
Did you include the header for QScrollBar in your class?

themanwiththequestion
2nd February 2010, 13:50
Did you include the header for QScrollBar in your class?

That seemed to be the reason. Thanks :)

A little strange the compiler didn't complain about unresolved type or sth like that.

franz
2nd February 2010, 14:33
It doesn't have to, because you're passing a pointer to it, which at that point is a resolved type. At that point it just doesn't know the QScrollBar is a QObject.