Notice also the sentence in docs:
So add a check for null pointer:Quote:
If connectionName does not exist in the list of databases, 0 is returned.
Code:
void GlavnoO::pushButton3_clicked() { bool ok = FALSE; if (baza) { ok = baza->isOpen(); } }
Printable View
Notice also the sentence in docs:
So add a check for null pointer:Quote:
If connectionName does not exist in the list of databases, 0 is returned.
Code:
void GlavnoO::pushButton3_clicked() { bool ok = FALSE; if (baza) { ok = baza->isOpen(); } }
Yep, that solves the segmentation fault. But I would still like to know how to acces databse connection which I opened in another form.
Sure, you're using Qt3 and I was looking at Qt4 docs.Quote:
Originally Posted by Lebowski
First check if addDatabase returns a valid database handle.Quote:
But I would still like to know how to acces databse connection which I opened in another form.
I did check with this code in form povezava (povezava.ui.h):
And it certainly works.Code:
bool ok = baza->open(); else { close(); };
But now I need to access it from a different form, from file glavnoo.ui.h.
So why don't you use QSqlDatabase::database()?
I am using that.
Originally it was without 'if (baza) ...' statement.Code:
void GlavnoO::test_clicked() { bool ok = FALSE; if (baza) { ok = baza->isOpen(); };
So what's wrong with that? The form you use it in doesn't matter. You can use QSqlDatabase::database() from anywhere. Just makesure addDatabase() has been invoked earlier.
Yep, it does work now!! Thanx all. :)
Seems I was missing QSqlDatabase::database() statement so my 'baza' pointer had a random value.