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. Hints about HTTP REST service vs database

Hints about HTTP REST service vs database

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 348 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.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by
    #1

    I hope I'm not off-topic here.
    I'm writing an application that has a background Qt Console application and a front-end PHP web page.
    If that matter, it runs on a custom Buildroot environment for Raspberry Pi 3, but my question can be related to any environment.

    The Qt application creates and updates some QList of custom struct, for example:

    typedef struct Song
    {
        Q_GADGET
        Q_PROPERTY(QString title MEMBER title)
        Q_PROPERTY(QString author MEMBER author)
        Q_PROPERTY(QString lyrics MEMBER lyrics)
        Q_PROPERTY(QString message MEMBER message)
        Q_PROPERTY(int rating MEMBER rating)
        Q_PROPERTY(QUrl cover MEMBER coverUrl)
    
    public:
        int id;
        QString file;
        QString title;
        QString author;
        QString lyrics;
        QString message;
        QString uuid;
        int rating;
        QImage cover;
        QUrl coverUrl;
    
        bool operator != (const Song &val)
        {
            if (val.title != this->title) return false;
            if (val.author != this->author) return false;
            if (val.lyrics != this->lyrics) return false;
            if (val.message != this->message) return false;
            if (val.rating != this->rating) return false;
            if (val.file != this->file) return false;
            return true;
        }
    } Song;
    Q_DECLARE_METATYPE(Song)
    

    This QList is read/edited by the Qt/QML application but it should be read also by the PHP page.
    I have two options, I've tried both but I'm not sure which one is better.

    a) Use a HTTP REST service in the Qt application
    I have to maintain only one storage (the QList) but the PHP page has to use a different port to GET the list at run-time and all the stuff to process the data should be done in JavaScript.

    b) Use a database
    The web page can fetch the data before create the page, but I have to keep in sync both the QList and the db table.

    Any thoughts about these approaches? What would you suggest?

    jsulmJ N 2 Replies Last reply
    0
    • M Mark81

      I hope I'm not off-topic here.
      I'm writing an application that has a background Qt Console application and a front-end PHP web page.
      If that matter, it runs on a custom Buildroot environment for Raspberry Pi 3, but my question can be related to any environment.

      The Qt application creates and updates some QList of custom struct, for example:

      typedef struct Song
      {
          Q_GADGET
          Q_PROPERTY(QString title MEMBER title)
          Q_PROPERTY(QString author MEMBER author)
          Q_PROPERTY(QString lyrics MEMBER lyrics)
          Q_PROPERTY(QString message MEMBER message)
          Q_PROPERTY(int rating MEMBER rating)
          Q_PROPERTY(QUrl cover MEMBER coverUrl)
      
      public:
          int id;
          QString file;
          QString title;
          QString author;
          QString lyrics;
          QString message;
          QString uuid;
          int rating;
          QImage cover;
          QUrl coverUrl;
      
          bool operator != (const Song &val)
          {
              if (val.title != this->title) return false;
              if (val.author != this->author) return false;
              if (val.lyrics != this->lyrics) return false;
              if (val.message != this->message) return false;
              if (val.rating != this->rating) return false;
              if (val.file != this->file) return false;
              return true;
          }
      } Song;
      Q_DECLARE_METATYPE(Song)
      

      This QList is read/edited by the Qt/QML application but it should be read also by the PHP page.
      I have two options, I've tried both but I'm not sure which one is better.

      a) Use a HTTP REST service in the Qt application
      I have to maintain only one storage (the QList) but the PHP page has to use a different port to GET the list at run-time and all the stuff to process the data should be done in JavaScript.

      b) Use a database
      The web page can fetch the data before create the page, but I have to keep in sync both the QList and the db table.

      Any thoughts about these approaches? What would you suggest?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Mark81 said in Hints about HTTP REST service vs database:

      but I have to keep in sync both the QList

      Why would you need a QList if you store the data in a database?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Mark81 said in Hints about HTTP REST service vs database:

        but I have to keep in sync both the QList

        Why would you need a QList if you store the data in a database?

        M Offline
        M Offline
        Mark81
        wrote on last edited by
        #3

        @jsulm because is easier to manipulate (i.e. get item, insert, reorder, shuffle) and it's easier to be read from QML. Otherwise, if I'm not wrong, I have to execute a query even for get the Nth element...

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

          Hi,

          Why would you need two ports to access a REST API from two different applications ?

          In any case, can you explain your architecture ? The Qt console application with a PHP front end and QML in the mix sounds at bit surprising.

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

          M 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            Why would you need two ports to access a REST API from two different applications ?

            In any case, can you explain your architecture ? The Qt console application with a PHP front end and QML in the mix sounds at bit surprising.

            M Offline
            M Offline
            Mark81
            wrote on last edited by
            #5

            @SGaist I try to explain it better, sorry if it was not so clear.

            I have:

            • apache2 to serve PHP/HTML pages
            • Qt application (I've just noticed I use the term "Console" improperly. I meant I don't use X server, but my application shows a QML page on the screen, though)

            The Qt application handles communications with the external world (i.e. using QSerialPort, or QFile) and maintain updated a "table" (currently the QList).

            The web application fetch the PHP pages on port 80 from the webserver (apache2). In order to provide a REST API from the Qt application I had to create another HTTP server (in Qt) that listen to a different port (i.e. 8080). In this way, the page itself is retrieve with a GET on port 80, while the run-time data can be fetch with another GET on port 8080.

            I hope now it's more clear!

            SGaistS 1 Reply Last reply
            0
            • M Mark81

              @SGaist I try to explain it better, sorry if it was not so clear.

              I have:

              • apache2 to serve PHP/HTML pages
              • Qt application (I've just noticed I use the term "Console" improperly. I meant I don't use X server, but my application shows a QML page on the screen, though)

              The Qt application handles communications with the external world (i.e. using QSerialPort, or QFile) and maintain updated a "table" (currently the QList).

              The web application fetch the PHP pages on port 80 from the webserver (apache2). In order to provide a REST API from the Qt application I had to create another HTTP server (in Qt) that listen to a different port (i.e. 8080). In this way, the page itself is retrieve with a GET on port 80, while the run-time data can be fetch with another GET on port 8080.

              I hope now it's more clear!

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              So your Qt application is responsible for feeding some data that can then be shown in a web browser to remote machines and you want to keep things in sync, is that so ?

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

              M 1 Reply Last reply
              0
              • SGaistS SGaist

                So your Qt application is responsible for feeding some data that can then be shown in a web browser to remote machines and you want to keep things in sync, is that so ?

                M Offline
                M Offline
                Mark81
                wrote on last edited by
                #7

                @SGaist exactly, but the same data is also shown on the QML pages. Here my confusion about which architecture is better. QList is easier for QML but database is easier for PHP.

                If I use both I have to keep them in sync, otherwise I have to "convert" them on the fly: i.e. executing a query every time I need anything on the Qt side.

                SGaistS 1 Reply Last reply
                0
                • M Mark81

                  @SGaist exactly, but the same data is also shown on the QML pages. Here my confusion about which architecture is better. QList is easier for QML but database is easier for PHP.

                  If I use both I have to keep them in sync, otherwise I have to "convert" them on the fly: i.e. executing a query every time I need anything on the Qt side.

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  You can use a QSqlTableModel subclass to feed your Qt application with database data.

                  Since the main active component will be your Qt application, it will also be simpler. You will update the database from Qt and the web application will be responsible to update itself when new data arrive in the database.

                  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
                  1
                  • M Mark81

                    I hope I'm not off-topic here.
                    I'm writing an application that has a background Qt Console application and a front-end PHP web page.
                    If that matter, it runs on a custom Buildroot environment for Raspberry Pi 3, but my question can be related to any environment.

                    The Qt application creates and updates some QList of custom struct, for example:

                    typedef struct Song
                    {
                        Q_GADGET
                        Q_PROPERTY(QString title MEMBER title)
                        Q_PROPERTY(QString author MEMBER author)
                        Q_PROPERTY(QString lyrics MEMBER lyrics)
                        Q_PROPERTY(QString message MEMBER message)
                        Q_PROPERTY(int rating MEMBER rating)
                        Q_PROPERTY(QUrl cover MEMBER coverUrl)
                    
                    public:
                        int id;
                        QString file;
                        QString title;
                        QString author;
                        QString lyrics;
                        QString message;
                        QString uuid;
                        int rating;
                        QImage cover;
                        QUrl coverUrl;
                    
                        bool operator != (const Song &val)
                        {
                            if (val.title != this->title) return false;
                            if (val.author != this->author) return false;
                            if (val.lyrics != this->lyrics) return false;
                            if (val.message != this->message) return false;
                            if (val.rating != this->rating) return false;
                            if (val.file != this->file) return false;
                            return true;
                        }
                    } Song;
                    Q_DECLARE_METATYPE(Song)
                    

                    This QList is read/edited by the Qt/QML application but it should be read also by the PHP page.
                    I have two options, I've tried both but I'm not sure which one is better.

                    a) Use a HTTP REST service in the Qt application
                    I have to maintain only one storage (the QList) but the PHP page has to use a different port to GET the list at run-time and all the stuff to process the data should be done in JavaScript.

                    b) Use a database
                    The web page can fetch the data before create the page, but I have to keep in sync both the QList and the db table.

                    Any thoughts about these approaches? What would you suggest?

                    N Offline
                    N Offline
                    NikoC
                    wrote on last edited by
                    #9

                    For your setup involving a Qt application and a PHP web page, using a database seems like the smoother path. Your web page can retrieve data as needed, while you maintain data consistency by syncing the database with your QList in the Qt app. This way, both your Qt app and web page stay on the same page with the data.

                    Empower your tech journey with valuable insights from https://softwaretested.com/

                    1 Reply Last reply
                    1

                    • Login

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