Results 1 to 8 of 8

Thread: Saving and storing data,QtSql

  1. #1
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Saving and storing data,QtSql

    Hi,
    i have a question is it possible to save and store data so that whenever the application starts it can be loaded by using QSqlTableModel..or by anyother QtSqls ??

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving and storing data,QtSql

    Yes, it is possible. Read about QSettings, especially about QSettings::registerFormat.

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

    Default Re: Saving and storing data,QtSql

    if you want use SQL just create a SQLite database and use it whenever you want.

  4. #4
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Saving and storing data,QtSql

    the question i am asking doesnt directly corresponds with the heading of topic..but still it is somehow regarding the same problem so i will ask it here..
    whats the problem in this piece of code..the table view changes from total white screen to a screen with a hash sign at the begiinning and whole white

    Qt Code:
    1. sqlModel->setTable("notes");
    2. sqlModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    3. int row =0;
    4. sqlModel->insertRows(row,1);
    5. sqlModel->setData(sqlModel->index(row,0),topicValue);
    6. sqlModel->setData(sqlModel->index(row,1),dateValue);
    7. sqlModel->setData(sqlModel->index(row,2),dataValue);
    8. sqlModel->submitAll();
    9. tableView->show();
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Saving and storing data,QtSql

    i copied the above code from a book and it didnt worked ...i have modified the code a bit and now it shows the table in my desired orientation but without the datas in it..i will paste it here

    Qt Code:
    1. constructor
    2. {
    3. ..
    4. sqlModel->setHeaderData(0,Qt::Horizontal,"Topic");
    5. sqlModel->setHeaderData(1,Qt::Horizontal,"Date");
    6. sqlModel->setHeaderData(2,Qt::Horizontal,"Data");
    7.  
    8. sqlModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
    9. sqlModel->insertColumns(column,3);
    10. ..
    11. }
    12.  
    13. void NoteBook::addRecord()
    14. {
    15. sqlModel->insertRows(row,1);
    16. sqlModel->setData(sqlModel->index(row,0),QVariant(topicValue));
    17. sqlModel->setData(sqlModel->index(row,1),QVariant(dateValue));
    18. sqlModel->setData(sqlModel->index(row,2),QVariant(dataValue));
    19. tableView->setModel(sqlModel);
    20. sqlModel->submitAll();
    21. ++row;
    22. tableView->show();
    23. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving and storing data,QtSql

    In addRecord() where are the values of your 3 QVariants being set?

  7. #7
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Saving and storing data,QtSql

    can u please come again..i didntunderstand...if u mean topicvalue ,datavalue and datevalue..then i have taken a line edit and taken an input from user and stored in it...

  8. #8
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Saving and storing data,QtSql

    I jus debugged this piece of code and the compiler said no signal generated..
    here topic is QlineEdit and i wanna see if the line changes so i can save the values of line to my variable...

    Qt Code:
    1. if( connect(&topic,SIGNAL(textChanged(QString &)),this,SLOT(setText(QString &))))
    2. {topicValue = topic.text();}
    3.  
    4. if( connect(&date,SIGNAL(textChanged(QString &)),this,SLOT(setText(QString &))))
    5. {dateValue = date.text();}
    6.  
    7. if( connect(&data,SIGNAL(textChanged(QString &)),this,SLOT(setText(QString &))))
    8. {dataValue = data.text();
    9. qDebug() << dateValue;
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 6
    Last Post: 20th January 2010, 05:16
  2. storing data in hexadecimal format
    By aj2903 in forum Qt Programming
    Replies: 6
    Last Post: 13th January 2010, 06:29
  3. QtSql data type mappings
    By eclarkso in forum Qt Programming
    Replies: 2
    Last Post: 16th December 2009, 18:22
  4. Replies: 1
    Last Post: 3rd December 2009, 10:20
  5. Saving hierarchical structures of data.
    By psih128 in forum Qt Programming
    Replies: 1
    Last Post: 30th July 2009, 09:33

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.