Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Database connectivity
Forum Updated to NodeBB v4.3 + New Features

Database connectivity

Scheduled Pinned Locked Moved Mobile and Embedded
13 Posts 4 Posters 6.0k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    preeth
    wrote on last edited by
    #1

    hello..,we are developing a project on intel embedded kit. the problem is we need to read the data in client side.and need to store the data at the server side database.
    . we are familiar with sqlite and mysql. Since we are new to qt finding it very difficult to connect to the database. So please help us.We r successful in creating the database at the client side.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      daliusd
      wrote on last edited by
      #2

      You have given very rough description what you need:

      1. In client side you have two options:

        a) if you are using Qt in C++ then you can anything what's related to DB (e.g. http://qt-project.org/doc/qt-4.8/database.html). Most probably you just need to create local SQLite DB. I think googling for tutorial is way to go.

        b) If you are using QML you can use Database API. Read here: http://doc.qt.digia.com/4.7-snapshot/qdeclarativeglobalobject.html#database-api

      2. It is not clear what problem you have on server side and what server you have in mind (Database server or some web/web service server). If you have in mind database server look what Qt has to offer. As well it is unclear what kind of DB Server you have: some servers offers HTTP(S) access what might be used using alternative approaches.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qxoz
        wrote on last edited by
        #3

        hi preeth!
        I'm not familiar with intel embedded kit, but i think link below can be a good start point:
        "http://qt-project.org/doc/qt-4.8/sql-driver.html":http://qt-project.org/doc/qt-4.8/sql-driver.html

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Qt supports connecting with server-type databases like MySql just fine, however, you will need to build the driver yourself (I think due to some legal concerns). The source code is there with your Qt sources.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            preeth
            wrote on last edited by
            #5

            @daliusd: our project is generating a hotel menu using touch interface...we are using intel atom kit...'
            customer will be ordering the menu at the client side and server end will have the database..chefs pc also will be accessing the data...this our project in short...
            we are doing the front end now...we are able to code for server part(server being the localhost)..like connecting to the database..but if server and client are located at different places where to specify the ip address ..so can u please suggest code for accessing the database located at separate server.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              daliusd
              wrote on last edited by
              #6

              OK. I see. My recommendation: create simple RESTful HTTP service that connects to DB. Now I think it is simpler to make client configurable: just add possibility to point client to server and that's it. You can give clients with predefined server value to customers because I guess you are in control here. Add possibility to save most commonly used servers (even if there is just single one now).

              If you still want to make server discoverable you can look into broadcast/multicast but that will work only if client and server are in the same local network. As well it creates more problems in the end than solves (I'm saying that from my experience).

              1 Reply Last reply
              0
              • P Offline
                P Offline
                preeth
                wrote on last edited by
                #7

                @daliusd: thanks a lot for the help..but we are new to qt so it would helpful if you could give us a code snippet of the same...

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  daliusd
                  wrote on last edited by
                  #8

                  I'm not sure what you are asking for. Based on what you have written start learning Qt Quick (QML + JS). Go through tutorials and examples and try writing something. E.g. this http://doc.qt.digia.com/qt/declarative-tutorials-samegame-samegame4.html explains how to communicate with HTTP server from Qt Quick app. You can find more examples.

                  Now HTTP server/service itself is out of scope of Qt. You can use PHP, Node.js, ASP.NET, Python or almost anything else. Use whatever you understand (this way you will end up with cheapest solution for you).

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    preeth
                    wrote on last edited by
                    #9

                    I have written a program that needs to connect to a sqlite db installed on one of the computers in the network. All others computers in the network running the program should be able to connect to the db.

                    I have a script that connect to the server, it looks like this:

                    Source code
                    @
                    #include <QMessageBox>
                    #include <QSqlDatabase>
                    #include <QSqlError>
                    #include <QSqlQuery>
                    #include <QFile>
                    #include <QTextStream>
                    #include <QString>

                    static bool createConnection()
                    {
                    QFile file;
                    file.setFileName("connection.txt");
                    if (!file.open(QFile::ReadOnly| QFile::Text)) {
                    QMessageBox::critical(0, qApp->tr("Error"),
                    qApp->tr("Cannot open connection file."
                    "Click Cancel to exit."), QMessageBox::Cancel);
                    return false;
                    }

                    QTextStream in(&file);

                    QString DatabaseName = in.readLine();
                    QString UserName = in.readLine();
                    QString Password = in.readLine();
                    QString HostName = in.readLine();

                    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
                    db.setDatabaseName( DatabaseName );
                    db.setUserName( UserName );
                    db.setPassword( Password );
                    db.setHostName( HostName );

                    if (!db.open()) {
                        QMessageBox::critical(0, qApp->tr("Cannot open database"),
                        qApp->tr("Unable to establish a database connection."
                        "Click Cancel to exit."), QMessageBox::Cancel);
                        return false;
                    

                    }

                    return true;
                    

                    }

                    #endif
                    @

                    The program works when running on the computer where SQLITE is installed but fails to connect when running on all the computers in the network.

                    I am using the ip address of the SQLITE server as hostname.

                    Hope that someone could help me out in this. By the way the database is running on UBUNTU machine and I am using SQLITE 3.

                    Edit: please put @ tags around code sections to make them easier to read; Andre

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #10

                      SQLite is not a database server, it is a file-based database. You cannot connect to a database by setting a host and a port as if it is running as a service on a different system. It is just a file. If you can access it through the file system, you can access the database.

                      I'd recommend not using SQLite for networked purposes. SQLite is meant for simple local data stores. Use a real database server like MySQL or PostgreSQL for something like this.

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        daliusd
                        wrote on last edited by
                        #11

                        [quote author="Andre" date="1359788658"]
                        I'd recommend not using SQLite for networked purposes. SQLite is meant for simple local data stores.[/quote]

                        Andre, you are not exactly right http://www.sqlite.org/whentouse.html and it might work in preeth's case. However, preeth, don't use SQLite like that. You don't have enough experience clearly. Use MySQL, Percona, MariaDB or PostreSQL.

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          andre
                          wrote on last edited by
                          #12

                          [quote author="daliusd" date="1359791075"][quote author="Andre" date="1359788658"]
                          I'd recommend not using SQLite for networked purposes. SQLite is meant for simple local data stores.[/quote]

                          Andre, you are not exactly right http://www.sqlite.org/whentouse.html and it might work in preeth's case. [/quote]
                          Clearly, preeth's setup is a client/server setup. That is listed as point 1 under "When another DBMS may work better".

                          Note that it is possible to use SQLite over a network, as long as you make sure you map the resource into the local file system (via NFS, SMB or whatever). In my experience: not all that stable, especially if your network is not very reliable.

                          1 Reply Last reply
                          0
                          • D Offline
                            D Offline
                            daliusd
                            wrote on last edited by
                            #13

                            [quote author="Andre" date="1359801847"]
                            [quote author="daliusd" date="1359791075"][quote author="Andre" date="1359788658"]
                            I'd recommend not using SQLite for networked purposes. SQLite is meant for simple local data stores.[/quote]

                            Andre, you are not exactly right http://www.sqlite.org/whentouse.html and it might work in preeth's case. [/quote]
                            Clearly, preeth's setup is a client/server setup. That is listed as point 1 under "When another DBMS may work better".

                            Note that it is possible to use SQLite over a network, as long as you make sure you map the resource into the local file system (via NFS, SMB or whatever). In my experience: not all that stable, especially if your network is not very reliable.

                            [/quote]

                            In short, I agree that preeth shouldn't use SQLite the way he/she wants to. I just wanted to point that SQLite might work for web sites as well as long as you understand what you are doing.

                            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