PDA

View Full Version : Saving and storing data,QtSql



salmanmanekia
20th April 2010, 13:39
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 ??

Lesiok
20th April 2010, 14:19
Yes, it is possible. Read about QSettings (http://doc.trolltech.com/4.6/qsettings.html), especially about QSettings::registerFormat (http://doc.trolltech.com/4.6/qsettings.html#registerFormat).

Lykurg
20th April 2010, 14:55
if you want use SQL just create a SQLite database and use it whenever you want.

salmanmanekia
20th April 2010, 15:28
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


sqlModel->setTable("notes");
sqlModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
int row =0;
sqlModel->insertRows(row,1);
sqlModel->setData(sqlModel->index(row,0),topicValue);
sqlModel->setData(sqlModel->index(row,1),dateValue);
sqlModel->setData(sqlModel->index(row,2),dataValue);
sqlModel->submitAll();
tableView->show();

salmanmanekia
20th April 2010, 17:36
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


constructor
{
..
sqlModel->setHeaderData(0,Qt::Horizontal,"Topic");
sqlModel->setHeaderData(1,Qt::Horizontal,"Date");
sqlModel->setHeaderData(2,Qt::Horizontal,"Data");

sqlModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
sqlModel->insertColumns(column,3);
..
}

void NoteBook::addRecord()
{
sqlModel->insertRows(row,1);
sqlModel->setData(sqlModel->index(row,0),QVariant(topicValue));
sqlModel->setData(sqlModel->index(row,1),QVariant(dateValue));
sqlModel->setData(sqlModel->index(row,2),QVariant(dataValue));
tableView->setModel(sqlModel);
sqlModel->submitAll();
++row;
tableView->show();
}

JD2000
20th April 2010, 18:50
In addRecord() where are the values of your 3 QVariants being set?

salmanmanekia
20th April 2010, 18:59
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...

salmanmanekia
20th April 2010, 19:08
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...


if( connect(&topic,SIGNAL(textChanged(QString &)),this,SLOT(setText(QString &))))
{topicValue = topic.text();}

if( connect(&date,SIGNAL(textChanged(QString &)),this,SLOT(setText(QString &))))
{dateValue = date.text();}

if( connect(&data,SIGNAL(textChanged(QString &)),this,SLOT(setText(QString &))))
{dataValue = data.text();
qDebug() << dateValue;

}