Results 1 to 9 of 9

Thread: Release ok, debug crashes [compilable code]

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    54
    Thanked 2 Times in 2 Posts

    Default Release ok, debug crashes [compilable code]

    Hi everyone,

    I'm here to provide you some fun
    Take this code and paste it in a QPushButton::clicked() slot
    Qt Code:
    1. mydb db1;
    2. if(db1.open())
    3. QMessageBox::information(this,"DEBUG info","Connected");
    4. db1.close();
    To copy to clipboard, switch view to plain text mode 
    then paste this somewhere in the .h or .cpp as you prefer
    Qt Code:
    1. class mydb{
    2. private:
    3. QVector<QSqlDatabase*> *handle;
    4. public:
    5. mydb(){ handle=new QVector<QSqlDatabase*>(); }
    6. ~mydb(){ delete handle; }
    7. bool open()
    8. {
    9. QSqlDatabase handle=QSqlDatabase::addDatabase("QMYSQL","connName");
    10. handle.setHostName("host");
    11. handle.setDatabaseName("db");
    12. handle.setUserName("username");
    13. handle.setPassword("password");
    14. handle.open();
    15. this->handle->append(&handle);
    16. return handle.isOpen();
    17. }
    18.  
    19. void close()
    20. {
    21. QSqlDatabase *h=handle->at(0);
    22. if(h->isValid())
    23. qDebug() << "Valid";
    24. if(h->isOpen())
    25. qDebug() << "Open";
    26. h->close();
    27. handle->remove(0);
    28. }
    29. };
    To copy to clipboard, switch view to plain text mode 
    includes
    Qt Code:
    1. #include <QtGui>
    2. #include <QtSql>
    3. // these are enhough, don't forget QT+=sql in file .pro
    To copy to clipboard, switch view to plain text mode 
    I'm compiling with mingw and running under Windows Xp SP3.
    To me this code runs clearly in release and raises exception in debug.
    Switching between modes with QtCreator causes it to change behavior.

    I see nothing wrong in code... maybe you can notice something I'm missing.

    Have fun
    Last edited by Raccoon29; 10th December 2009 at 14:51. Reason: reformatted to look better
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

Similar Threads

  1. Replies: 3
    Last Post: 3rd December 2009, 16:12
  2. Replies: 1
    Last Post: 18th November 2009, 21:51
  3. Replies: 5
    Last Post: 5th October 2008, 05:12
  4. Need debug and release versions of Qwt?
    By Tiansen in forum Qwt
    Replies: 1
    Last Post: 28th March 2008, 07:55
  5. Replies: 6
    Last Post: 10th November 2006, 10:38

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
  •  
Qt is a trademark of The Qt Company.