How check fast, if database reachable? (Qt, QML, C++)- Linux -


i use qt qml , c++. on application use database. works, if database reachable.

my problem is, check, if database reachable (like ping).

i tried

    db.setdatabasename(dsn);     if(db.isvalid())     {          if(db.open())         {             //std::cout <<"offene datenbank";             connected=true;          }         else         {             connected=false;         }       }     else     {         connected=false;     } 

and give connected value result. takes long (maybe 30 seconds), if there no connection. how can check fast, if have database connection?

is there maybe way break command .open after 5 seconds not connected?

i think 1 easy solution check ping of database sever. can use platform specific ways pinging.

this work on linux :

int exitcode = qprocess::execute("ping", qstringlist() << "-c 2" << serverip); if (exitcode==0)  {     // reachable } else  {     // not reachable } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -