SQLite Remote connection data
1. Connect to local Database
Qsqldatabase db =qsqldatabase::adddatabase ("Qsqlite");
Db.setdatabasename ("personnel.db");
Db.setusername ("Persionsql");//database user name and password
Db.setpassword ("123456");
if (!db.open ()) {
Qmessagebox::warning (0,qobject::tr ("Database Error"),
Db.lasterror (). text ());
return false;
}
Open the database under the current directory, or create a database named Personnel.db if it is not.
2, SQLite connect the local shared database
Qsqldatabase db = Qsqldatabase::adddatabase ("Qsqlite");
Db.sethostname ("localhost");//Set your local server's IP
Db.setdatabasename ("/sqllitedb/personnel.db");//Sqllitedb The name of the database under the shared directory
Db.setusername ("Persionsql");//database user name and password
Db.setpassword ("123456");
if (!db.open ())
Qdebug () << "Failed to connect to Qsqlite";
Else
Qdebug () << "success!";
Open the shared database under your native Sqllitedb directory, and if not, the open fails.
If you have the database in the shared directory, the Open is successful.
3, SQLite connection network sharing database
Qsqldatabase db =qsqldatabase::adddatabase ("Qsqlite");
Db.sethostname ("192.168.1.160");//Set the IP of your Web server
Db.setdatabasename ("/share/personnel.db");//share the name of the database under the shared directory
Db.setusername ("Persionsql");//database user name and password
Db.setpassword ("123456");
if (!db.open ())
Qdebug () << "Failed to connect to Qsqlite";
Else
Qdebug () << "success!";
Open the shared database under your network shared directory share, and if not, the open fails.
If you have the database in the shared directory, the Open is successful.
Note: Access to the network remote database must shut down the firewall on both the local and remote PC, the path of the remote database to be accessed cannot be a Chinese path, and the shared directory must have readable writable permissions.
SQLite Remote Connection