Results 1 to 5 of 5

Thread: Compiler error when calling QObject::connect. What am I missing?

  1. #1
    Join Date
    Feb 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Compiler error when calling QObject::connect. What am I missing?

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

    Qt Code:
    1. MyClass::MyClass(QWidget * parent, Qt::WindowFlags f): QDialog(parent, f)
    2. {
    3. _widget.setupUi(this);
    4.  
    5. _imageScene = new QGraphicsScene;
    6.  
    7. _widget.graphicsView->setScene(_imageScene);
    8.  
    9. //This works
    10. connect(_widget.imageListView->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(currentImageChanged(const QModelIndex&)));
    11.  
    12. //These two are causing the compiler errors
    13. connect(_widget.graphicsView->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(updateVisibleRect()));
    14. connect(_widget.graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(updateVisibleRect()));
    15. }
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. src/MyClass.cpp:58: error: no matching function for call to `MyClass::connect(QScrollBar*, const char*, MyClass* const, const char*)'
    2.  
    3. 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)
    4.  
    5. 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
    6.  
    7. src/MyClass.cpp:59: error: no matching function for call to `MyClass::connect(QScrollBar*, const char*, FATThresholdDialog* const, const char*)'
    8.  
    9. 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)
    10.  
    11. 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
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Compiler error when calling QObject::connect. What am I missing?

    Post Deleted
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Nov 2008
    Posts
    142
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Compiler error when calling QObject::connect. What am I missing?

    Did you include the header for QScrollBar in your class?

  4. #4
    Join Date
    Feb 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Compiler error when calling QObject::connect. What am I missing?

    Quote Originally Posted by rexi View Post
    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.

  5. #5
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Compiler error when calling QObject::connect. What am I missing?

    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.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

Similar Threads

  1. Issue using connect, what am I missing?
    By technoViking in forum Qt Programming
    Replies: 1
    Last Post: 11th January 2010, 06:11
  2. [Help] QObject::connect
    By vinny gracindo in forum Newbie
    Replies: 3
    Last Post: 20th October 2009, 14:26
  3. QObject::connect stalls
    By arkain in forum Qt Programming
    Replies: 2
    Last Post: 26th April 2009, 01:26
  4. Replies: 4
    Last Post: 10th November 2006, 16:38
  5. QStringList in QObject::connect
    By DPinLV in forum Qt Programming
    Replies: 6
    Last Post: 6th September 2006, 18:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.