Results 1 to 7 of 7

Thread: QTimer and QSqlDatabase Problem

  1. #1
    Join Date
    Jun 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QTimer and QSqlDatabase Problem

    Hi

    I am currently writing an app that reads information from a database, displays it to a screen, delays for x amount of seconds, then displays some different information.

    I'm using QTimer to hadle the dealy but am running into some issues regarding the
    QSqlDatabase.

    What I do is this:

    Qt Code:
    1. main()
    2. {
    3. create and open database
    4. call screen1();
    5. }
    6.  
    7. screen1()
    8. {
    9. read info from database;
    10. display;
    11. QTimer::singleShot(5000,this,screen2());
    12. }
    13.  
    14. screen2()
    15. {
    16. read info from db;
    17. display;
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 

    The first display method (screen1) works perfectly. However, the second method fails and says "Database not open". If I remove the line with "QTimer::single..." in it and replace it with "screen2();", then it works perfectly, just with no delay, which is obviously a bummer.

    I don't understand the deep inner workings of either of these classes so if someone more knowledgable could perhaps point out why they "appear" to be interfering with each other.

    They may well nt be, but, as I said, the fact that removing that line removes the problem tend to suggest as such.

    Thanks
    G

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTimer and QSqlDatabase Problem

    Do you create any objects on the stack in screen1()? Is the call to QTimer::singleShot() in the last line or maybe screen1() does something afterwards?

  3. #3
    Join Date
    Jun 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTimer and QSqlDatabase Problem

    I don't explicitly create anything on the stack.
    And yes, that is the last line in screen1().

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTimer and QSqlDatabase Problem

    Do you use any static or global variables?

  5. #5
    Join Date
    Jun 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTimer and QSqlDatabase Problem

    The only global variable is the reference to the database.

  6. #6
    Join Date
    Jun 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTimer and QSqlDatabase Problem

    OK, I seem to have solved it, but I'm interested to know how.

    Turns out I had another, half written method called mainLoop() that I was going to call later (note: I never called it in my code) which had, as part of it's instructions, a query call and a close call to the DB. If I comment out that method the code works perfectly.
    It's a bit weird, but I'll take it and run.

    Thanks for the help.
    Cheers
    G

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTimer and QSqlDatabase Problem

    Quote Originally Posted by smtgra011 View Post
    Turns out I had another, half written method called mainLoop() that I was going to call later (note: I never called it in my code) which had, as part of it's instructions, a query call and a close call to the DB.
    It's hard to say anything without seeing your code.

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.