Results 1 to 2 of 2

Thread: Print out graphics item type information

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Posts
    212
    Thanks
    24
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Print out graphics item type information

    Hello forum,

    I am having issues while printing out the graphics item type information. I want to print the verbose information not the numeric one.

    Is there any mechanism in Qt to print the graphics item type, something like the following:


    Qt Code:
    1. qDebug () << "Item type: " << item->type() << endl;
    To copy to clipboard, switch view to plain text mode 


    The above code gives me the numeric value, i would like to have something verbose


    Regards
    Sajjad

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Print out graphics item type information

    You can use the typeid operator to print the class name of any object:
    Qt Code:
    1. #include <QApplication>
    2. #include <QtCore>
    3. #include <QDebug>
    4. #include <QtGui>
    5. #include <typeinfo>
    6.  
    7. class MyClass
    8. {
    9. };
    10.  
    11. int main(int argc, char **argv) {
    12.  
    13. QApplication app(argc,argv);
    14. MyClass m;
    15.  
    16. qDebug() << typeid(line).name() << typeid(rect).name();
    17. qDebug() << typeid(app).name() << typeid(m).name();
    18.  
    19. return 0;
    20. }
    To copy to clipboard, switch view to plain text mode 
    remember to #include <typeinfo>. The output depends on the compiler, so use this carefully (don't make any assumptions about this value, just use it for your information only):
    17QGraphicsLineItem 17QGraphicsRectItem
    12QApplication 7MyClass

  3. The following user says thank you to stampede for this useful post:

    sajis997 (24th January 2012)

Similar Threads

  1. Graphics item highlight
    By mukunda in forum Qt Programming
    Replies: 1
    Last Post: 8th April 2011, 18:21
  2. Graphics Item
    By Maluko_Da_Tola in forum Newbie
    Replies: 4
    Last Post: 20th July 2010, 14:37
  3. Serialization and graphics item
    By prashant in forum Qt Programming
    Replies: 1
    Last Post: 12th November 2009, 11:03
  4. Graphics item position after drag
    By Miihkali in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2009, 10:01
  5. Reimplementing The MousePressEvent for Graphics Item
    By ashishrai in forum Qt Programming
    Replies: 3
    Last Post: 25th May 2008, 20:11

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.