[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
historymanager::historymanager(QObject *parent) :
database = QSqlDatabase::addDatabase("QSQLITE");
bool ok = database.open();
qDebug() << ok;
query = new QSqlQuery(database);
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 + ")");
Add @Q_CHECK_PTR(query)@ before every @query->exec(..);@ instance. If you have false in your App Output - it should be SIGSEGV on broken pointer.
sorry man it is not working
the pointer is fine as it does not outputs anything
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().
it works lukas geyer i did not see that you are awesome thanks man
Feel free to prepend the post title with [Solved] (just edit your initial post), as an indication that your problem has been solved and that there is a solution inside.