Results 1 to 11 of 11

Thread: Very Simple QGraphicsView Example for QT5.7 QtCreator mainwindow's main.cpp

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2016
    Posts
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Very Simple QGraphicsView Example for QT5.7 QtCreator mainwindow's main.cpp

    Could someone please point me to a very simple QGraphicsView Example for QT5.7 QtCreator mainwindow's main.cpp that actually works and doesn't throw a "no matching function for call" error.

    I've read the documentation for QGraphicsView, QGraphicsScene, and QGraphicsItem. I've tried various code published here and elsewhere which is supposed to work. But everything seems to throw that error.

    For example, I start a new Qt widgets application in Qt Creator. I change nothing except main.cpp, which becomes:

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QApplication>
    3. #include <QGraphicsItem>
    4. #include <QGraphicsScene>
    5. #include <QGraphicsView>
    6.  
    7. int main( int argc, char **argv )
    8. {
    9. QApplication app(argc, argv);
    10.  
    11. QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 100, 100));
    12.  
    13. QGraphicsItem *item = scene.itemAt(50, 50);
    14. // item == rect
    15.  
    16. QGraphicsView view(&scene);
    17. view.show();
    18.  
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 

    At the line:

    Qt Code:
    1. QGraphicsItem *item = scene.itemAt(50, 50);
    To copy to clipboard, switch view to plain text mode 

    I get "no matching function for call to 'QGraphicsScene::itemAt(int,int)'.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Very Simple QGraphicsView Example for QT5.7 QtCreator mainwindow's main.cpp

    The compiler gave you the reason it couldn't compile this.

    There is no such method.

    You are probably trying to call this one http://doc.qt.io/qt-5/qgraphicsscene.html#itemAt-3

    If you look at the full error message, it even tells you why it couldn't select that one

    /dvl/Qt5.7.0/5.7/gcc_64/include/QtWidgets/qgraphicsscene.h:179:27: note: candidate: QGraphicsItem* QGraphicsScene::itemAt(qreal, qreal, const QTransform&) const
    inline QGraphicsItem *itemAt(qreal x, qreal y, const QTransform &deviceTransform) const
    ^
    /dvl/Qt5.7.0/5.7/gcc_64/include/QtWidgets/qgraphicsscene.h:179:27: note: candidate expects 3 arguments, 2 provided
    Cheers,
    _

  3. #3
    Join Date
    Apr 2016
    Posts
    23
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Very Simple QGraphicsView Example for QT5.7 QtCreator mainwindow's main.cpp

    Thank you -

    I'll look into that.

    But, my copy of Qt 5.7 QtCreator 4.0.2 didn't give me all of that error message. All I got was:

    "C:\work\Qt5Work\Qt570\LearningTests\QGraphicsView FirstTest\main.cpp:14: error: no matching function for call to 'QGraphicsScene::itemAt(int, int)'
    QGraphicsItem *item = scene.itemAt(50, 50);"

    Is there some setting I need to adjust to get the more verbose error messages?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Very Simple QGraphicsView Example for QT5.7 QtCreator mainwindow's main.cpp

    Error messages depend on the compiler.
    In my case that is g++ 5.3.1

    Did you look at the compile output or just the issues tab?

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 29th February 2016, 14:19
  2. Problem with variable in main.cpp and mainwindow.cpp
    By adis1001 in forum Qt Programming
    Replies: 13
    Last Post: 14th July 2015, 10:03
  3. Refresh the mainwindow / functions called in the main loop
    By valerianst in forum Qt Programming
    Replies: 7
    Last Post: 2nd October 2013, 14:57
  4. Replies: 1
    Last Post: 29th April 2013, 07:56
  5. QGraphicsView + MainWindow
    By lioncub in forum Newbie
    Replies: 3
    Last Post: 26th February 2011, 10:31

Tags for this Thread

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.