Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How Can I connect to sqlite database on raspberry pi using lighttpd server



  • Hi all,

    I've installed lighttpd and sqlite on my raspberry pi.
    Now I want to access a database file (sqlite) stored in the Raspberry Pi which I can access using lighttpd server.
    I' ve done the following :

    const QString DRIVER("QSQLITE");
    
        if(QSqlDatabase::isDriverAvailable(DRIVER))
        {
            QSqlDatabase db = QSqlDatabase::addDatabase(DRIVER);
    
            db.setHostName("192.168.5.89"); //Rasberry IP
            db.setPort(80);
            db.setDatabaseName("test.db");
    
            if(!db.open())
            {
                qWarning() << "MainWindow::DatabaseConnect - ERROR: " << db.lastError().text();
            }
        }
        else
            qWarning() << "MainWindow::DatabaseConnect - ERROR: no driver " << DRIVER << " available";
    }
    

    I have no error on compilation, but I can't access to the database on the raspberry.
    Instead, when I launch the app, it create a local database file test.db in the same directory of the .exe .

    Thx!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Because that's not how it works with SQLite. SQLite is file based so if your really want to access that file on a remote machine, you should mount your remote server folder on your local machine and use that path to access your database. Neither setHostName nor setPort are used by the SQLite backend because they don't make any sense in that context.



  • Thank you @SGaist , I wonder if using php can figure it out. I mean if I use QNetworkAccessManager and connect to a php script placed on my webserver (lighttpd) and in that script I manage the database.


  • Lifetime Qt Champion

    Hi

    • QNetworkAccessManager and connect to a php script placed on my webserver

    well you can use sqllite as backend if you want.

    https://opensourceforu.com/2011/03/lighttpd-sqlite-lightweight-web-server-database-platform/

    alternative
    you can use QWebChannel to integrate
    https://doc.qt.io/qt-5/qtwebchannel-examples.html

    but are you sure you want to use sqllite for this ?
    Its really not meant for many concurrent connections.



  • Thx @mrjj , I think I will use php on my webserver. And for the SQlite, I have no choice because it's mandatory for the project that I'm working on.


Log in to reply