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
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