Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How Can I connect to sqlite database on raspberry pi using lighttpd server
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 963 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KLAI
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      5
      • K Offline
        K Offline
        KLAI
        wrote on last edited by
        #3

        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.

        mrjjM 1 Reply Last reply
        0
        • K KLAI

          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.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          3
          • K Offline
            K Offline
            KLAI
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved