Well it started with
db->isValid() // this works
db->isOpen() // this fails with segfault

so how do I check if I have a connection to the database?

Also, is it possible to create more persistant connections? I use PostgreSQL.