Results 1 to 4 of 4

Thread: lifespan of QSqlRecord?

  1. #1
    Join Date
    Nov 2008
    Posts
    183
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default lifespan of QSqlRecord?

    All,

    Quick question before I go down a coding bunny hole. Does anyone here know what the lifespan of a QSqlRecord is? This gives me pause:

    http://qt-project.org/doc/qt-4.8/qsq...ml#operator-eq
    QSqlRecord is implicitly shared. This means you can make copies of a record in constant time.

    I'm asking because I find myself in a situation where I need to pass in convoluted where clause strings to dynamically build an ugly SELECT which uses multiple LEFT JOIN SELECTS. (Don't ask. I was unable to successfully champion the idea of organizing the database the way it is actually needed vs. the way which takes up the smallest amount of storage.) The database access is in its own thread so the GUI never locks because of it. No problems there. What I've never done though is build a vector of QSqlRecord and return it (or reference to it).

    Does anyone know if a deep copy happens when the finish() is executed for the query or the commit() happens or the thread disconnects from database? An implicit share to something which doesn't "legally" exist anymore will cause random crashes, so, before I head down that path and burn a lot of time . . . anyone know the answer off top of their head?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: lifespan of QSqlRecord?

    QSqlRecord is strictly a data carrier class. It lives as long as its object lives. It has no lifespan relation to any of the database objects (QSqlDatabase or QSqlQuery).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    RolandHughes (9th February 2015)

  4. #3
    Join Date
    Nov 2008
    Posts
    183
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: lifespan of QSqlRecord?

    So, if I interpret your statement correctly, it is just like QString? The "implicitly shared" phrase made it sound like

    QSqlRecord r = q.record();
    vector.append(r);

    would leave a ghost inside of the vector.

    Thanks, I will code it up and give it a try.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: lifespan of QSqlRecord?

    Quote Originally Posted by RolandHughes View Post
    So, if I interpret your statement correctly, it is just like QString?
    Yes.
    The "implicitly shared" phrase made it sound like

    QSqlRecord r = q.record();
    vector.append(r);

    would leave a ghost inside of the vector.
    No, because append() makes a shallow copy of r. Exactly as QString, QColor or almost all other value classes in Qt.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QSqlRecord problem
    By Nefastious in forum Newbie
    Replies: 1
    Last Post: 15th October 2009, 17:30
  2. Seg fault QSqlRecord
    By giusepped in forum Qt Programming
    Replies: 4
    Last Post: 25th October 2008, 06:03
  3. Using qsqlrecord?
    By triperzonak in forum Qt Programming
    Replies: 2
    Last Post: 23rd July 2008, 11:04
  4. QSqlRecord becoming invalid
    By mikro in forum Newbie
    Replies: 5
    Last Post: 3rd October 2006, 18:00
  5. QSqlRecord problem
    By stevey in forum Qt Programming
    Replies: 2
    Last Post: 24th September 2006, 22:32

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.