Results 1 to 5 of 5

Thread: Can you add a custom object to a SQL database?

  1. #1
    Join Date
    May 2010
    Posts
    53
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    2

    Default Can you add a custom object to a SQL database?

    I have the following class:

    class siStore
    {
    public:
    siStore();
    ~siStore();

    QVector<float> *si;
    float siSum;
    float si2Sum;
    int length;
    int siWidth;
    }

    In my program I then create a QList<siStore*> called siStack.

    In practice, the application generates a "training set" called siStack based on a few training parameters and an input 3D surface mesh. Each surface mesh may require multiple "training sets" using differing parameters.

    I envision my database to look like this: Table1 =name[ modelID modelName], Table 2 = parameters[ paramID modelID Param1 Param2 ...], Table 3 = trainingSet[ paramID siStack].

    Is this possible, or even make sense? From what I read I need to use a BLOB type, but how do I convert my object to a BLOB and how to I later read the BLOB and convert it to a QList<siStore*>?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Can you add a custom object to a SQL database?

    Create a << and >> operator for your class siStore, then you can easily store your list siStack to a database and read it back in (using the operators...).

  3. #3
    Join Date
    May 2010
    Posts
    53
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    2

    Default Re: Can you add a custom object to a SQL database?

    That makes sense from what I have read, but how do I go about doing that? Could you give me a brief example?

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: Can you add a custom object to a SQL database?

    Try something like that as a starting point
    Qt Code:
    1. QDataStream& operator<<(QDataStream& stream, const siStore& class)
    2. {
    3. stream << siStore.siSum << class.si2Sum() << ...;
    4. return stream;
    5. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    May 2010
    Posts
    53
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    2

    Default Re: Can you add a custom object to a SQL database?

    hmm... Unfortunately I'm away from my development PC and am unable to try your suggestion. But just to make sure I understand everything correctly, you would append all the members of my class to a QDataStream which would then be a binary encoding and could directly be used as a BLOB? Something like this, where siStack is a BLOB:

    Qt Code:
    1. QSqlQuery query;
    2. query.prepare("INSERT INTO trainingSet (id, siStack) "
    3. "VALUES (:id, :siStack)");
    4. query.bindValue(":id", 1001);
    5. query.bindValue(":siStack", myQDataStream);
    6. query.exec();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. writing object to the file(Object Persistance)
    By jjbabu in forum Qt Programming
    Replies: 2
    Last Post: 11th June 2009, 15:28
  2. Open a QMainWindow Object in QDialog Object
    By chuengchuenghq in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2008, 07:33
  3. How can I save a QImage object into a SQLite3 database table?
    By danielperaza in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2008, 06:39
  4. updating database with custom delegate
    By Shaitan in forum Qt Programming
    Replies: 4
    Last Post: 17th July 2007, 11:34
  5. How to convert QVariant to my custom object?
    By troorl_ua in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2007, 19:59

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.