[solved]qt crashes on running QSqlQuery::exec()
-
qt is crashinbg when QSqlQuery::exec() it is charshing for any query bit if i remove it the program will work fine after debugging i got that the last task at which it chrashed was QSqlResult the program crashes on startup
@
#include "historymanager.h"
#include <QDebug>
historymanager::historymanager(QObject *parent) :
QObject(parent)
{
database = QSqlDatabase::addDatabase("QSQLITE");
database.setHostName("cute browser");
database.setUserName("cute browser");
database.setPassword("password");
bool ok = database.open();
qDebug() << ok;
createtablehistory();
query = new QSqlQuery(database);
}
bool historymanager::createtablehistory()
{
uery->exec("create table history(id integer primary key,firstname varchar(20),lastname varchar(30)age integer)");
}
bool historymanager::addhistory(QString title, QString url)
{
query->exec("insert into history(title ,url)VALUES(" + title + "," + url + ")");
}
@
the code -
You call <code>createtablehistory()</code> at #12, which uses <code>query</code>, but <code>query</code> is initialized in line #13. Swap both.
Q_CHECK_PTR() does not trap because a pointer, as almost every other variable, is not initialized with null (or initialized at all, unless explicitly done so); it will be purely coincidental if an unitialized pointer is null and therefore trapped by Q_CHECK_PTR().