Answer the question
In order to leave comments, you need to log in
What is the correct way to write QSqlQuery in Qt?
Question in requests.
here is my db
main:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qDebug() << QSqlDatabase::drivers();
Widget w;
w.show();
return a.exec();
}
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("D:/Qt projects/History/Base.db");
if(!db.open())
qDebug()<<"Cant open";
QSqlQuery query(db);
query.exec("select Qestion from History where id=0 and id=1 ");
bool res=query.prepare("select Qestion from History where id=0 and id=1 ");
qDebug()<<"res="<<res;
qDebug()<<"select"<<query.isSelect();
qDebug()<<"valid"<<query.isValid();
QString name;
name = query.value(0).toString();
qDebug()<<"name::"<<name;
ui->textEdit->setText(name);
ui->textEdit->setReadOnly(true);
}
}
Answer the question
In order to leave comments, you need to log in
Why query.prepare() after query.exec()?
Try query.next() after exec()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question