Results 1 to 2 of 2

Thread: How can i get the mentioned output

  1. #1
    Join Date
    May 2010
    Posts
    12
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default How can i get the mentioned output

    Qt Code:
    1. #include<QObject>
    2. #include<QString>
    3. #include<QDebug>
    4. #include<QApplication>
    5.  
    6. class VerboseObject : public QObject {
    7.  
    8. public:
    9. VerboseObject(QObject *parent, const QString& name):QObject(parent){
    10. parent->setObjectName(name);
    11. qDebug()<<"\n constructor \n";
    12. }
    13. ~VerboseObject() {
    14. qDebug()<<"\n Deleted"<<(*this).objectName()<<"\n";
    15. }
    16. void do_sthing() {
    17. qDebug()<<"\n do sthing"<<(*this).objectName()<<"\n";
    18. }
    19.  
    20.  
    21. };
    22.  
    23.  
    24. int main(int argc , char* argv[])
    25. {
    26. QApplication A(argc ,argv);
    27.  
    28. VerboseObject top(&A,"Top");
    29.  
    30. VerboseObject *x = new VerboseObject(&top,"x");
    31. VerboseObject *y = new VerboseObject(&top,"y");
    32. VerboseObject *z = new VerboseObject(&top,"z");
    33.  
    34. top.do_sthing();
    35. x->do_sthing();
    36. y->do_sthing();
    37. z->do_sthing();
    38.  
    39. return 0;
    40. }
    To copy to clipboard, switch view to plain text mode 

    I am expecting output:

    constructor
    constructor
    constructor
    constructor

    do sthing "Top"
    do sthing "x"
    do sthing "y"
    do sthing "z"

    Deleted "Top"
    Deleted "x"
    Deleted "y"
    Deleted "z"

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can i get the mentioned output

    Hi!

    Qt Code:
    1. #include<QObject>
    2. #include<QString>
    3. #include<QDebug>
    4. #include<QApplication>
    5.  
    6. class VerboseObject : public QObject {
    7.  
    8. public:
    9. VerboseObject(QObject *parent, const QString& name):QObject(parent){
    10. setObjectName(name);
    11. qDebug() << "constructor";
    12. }
    13. ~VerboseObject() {
    14. qDebug()<<"Deleted" <<(*this).objectName();
    15. }
    16. void do_sthing() {
    17. qDebug()<<"do sthing" <<(*this).objectName();
    18. }
    19.  
    20.  
    21. };
    22.  
    23.  
    24. int main(int argc , char* argv[])
    25. {
    26. QApplication A(argc ,argv);
    27.  
    28. VerboseObject top(&A,"Top");
    29.  
    30. VerboseObject *x = new VerboseObject(&top,"x");
    31. VerboseObject *y = new VerboseObject(&top,"y");
    32. VerboseObject *z = new VerboseObject(&top,"z");
    33.  
    34. top.do_sthing();
    35. x->do_sthing();
    36. y->do_sthing();
    37. z->do_sthing();
    38.  
    39. return 0;
    40. }
    To copy to clipboard, switch view to plain text mode 
    results in:

    Starting E:\Develop\QtCentre\ObjectDelete\ObjectDelete\debu g\ObjectDelete.exe... constructor
    constructor
    constructor
    constructor
    do sthing "Top"
    do sthing "x"
    do sthing "y"
    do sthing "z"
    Deleted "Top"
    Deleted "x"
    Deleted "y"
    Deleted "z"
    E:\Develop\QtCentre\ObjectDelete\ObjectDelete\debu g\ObjectDelete.exe exited with code 0

    You accidentaly set the objectname of the parent instead of the class itself. And you don't need line breaks. Each call to qDebug() automatically ends with a line break.

    Joh

Similar Threads

  1. How to get ffmpeg output
    By linuxoid in forum Newbie
    Replies: 2
    Last Post: 15th March 2012, 16:06
  2. Can't get QProcess output
    By croscato in forum Qt Programming
    Replies: 6
    Last Post: 18th November 2010, 15:56
  3. Replies: 1
    Last Post: 14th April 2007, 13:42
  4. qDebug() output
    By Doug Broadwell in forum Newbie
    Replies: 1
    Last Post: 1st November 2006, 21:54
  5. output UTF?
    By mikro in forum Newbie
    Replies: 4
    Last Post: 18th May 2006, 23:00

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.