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. Reading image from QSqlTableModel
Forum Updated to NodeBB v4.3 + New Features

Reading image from QSqlTableModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
53 Posts 8 Posters 20.9k Views 4 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #44

    @VRonin SQLite does since some times already and Qt 5.10 should have proper support for that. Until then, positional is the safest way as you wrote.

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

    G 1 Reply Last reply
    1
    • SGaistS SGaist

      @VRonin SQLite does since some times already and Qt 5.10 should have proper support for that. Until then, positional is the safest way as you wrote.

      G Offline
      G Offline
      gabor53
      wrote on last edited by gabor53
      #45

      @SGaist
      I redid the query like this:

      (ID,Name,Pic,What,Material,Color,Description,AdoptDate,Signed,History,Age,Notes)" "VALUES(?,?,?,?,?,?,?,?,?,?,?,?)");
        querys.bindValue (0, sIDReview);
        querys.bindValue (1, nameReview);
        querys.bindValue (2, fileByteArray);
        querys.bindValue (3, whatReview);
        querys.bindValue (4, materialReview);
        querys.bindValue (5, colorReview);
        querys.bindValue (6, descriptionReview);
        querys.bindValue (7, adoptDateStr);
        querys.bindValue (8, SignedbyReview);
        querys.bindValue (9, historyReview);
        querys.bindValue (10, ageReview);
        querys.bindValue (11, notesReview);
      
        bool result = querys.exec ();
      
      

      It gave me this error :

      Error inserting into the main db! QSqlError("", "Parameter count mismatch", "")
      External WM_DESTROY received for QWidgetWindow(0x24d75c10, name="ReviewWindow") , parent: QWindow(0x0) , transient parent: QWidgetWindow(0x24d7a4b0, name="AdditemWindow")

      Changing

       explicit Review(QWidget* parent = 0);
      

      to

       explicit Review(QWidget* parent = Q_NULLPTR);
      

      in review.h
      solved everything except the Parameter count mismatch.

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #46

        can you try using addBindValue instead of bindValue?

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        G 1 Reply Last reply
        0
        • VRoninV VRonin

          can you try using addBindValue instead of bindValue?

          G Offline
          G Offline
          gabor53
          wrote on last edited by
          #47

          @VRonin
          I changed as you recommended:

           querys.prepare ("INSERT INTO Items (ID,Name,Pic,What,Material,Color,Description,AdoptDate,Signed,History,Age,Notes)" "VALUES(?,?,?,?,?,?,?,?,?,?,?,?)");
            querys.addBindValue (sIDReview);
            querys.addBindValue (nameReview);
            querys.addBindValue (fileByteArray);
            querys.addBindValue (whatReview);
            querys.addBindValue (materialReview);
            querys.addBindValue (colorReview);
            querys.addBindValue (descriptionReview);
            querys.addBindValue (adoptDateStr);
            querys.addBindValue (SignedbyReview);
            querys.addBindValue (historyReview);
            querys.addBindValue (ageReview);
            querys.addBindValue (notesReview);
          
            bool result = querys.exec ();
          

          Still the same error message.

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

            Do you have anything null/invalid that you pass to addBindValue ?

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

            G 2 Replies Last reply
            1
            • SGaistS SGaist

              Do you have anything null/invalid that you pass to addBindValue ?

              G Offline
              G Offline
              gabor53
              wrote on last edited by
              #49

              @SGaist
              Nothing invalid, but I had a bunch of blank text fields which I'm sure translate into null.

              1 Reply Last reply
              0
              • SGaistS SGaist

                Do you have anything null/invalid that you pass to addBindValue ?

                G Offline
                G Offline
                gabor53
                wrote on last edited by
                #50

                @SGaist
                Even when I fill out each field I get the same error.

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

                  Don't you have a missing space in your query between the ) and VALUES ?

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

                  G 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Don't you have a missing space in your query between the ) and VALUES ?

                    G Offline
                    G Offline
                    gabor53
                    wrote on last edited by
                    #52

                    @SGaist
                    I tried to add space between the " " or ) " but made no difference.
                    I rebuilt the db and now the images are displayed, but they are all rotated 90° left; no idea why.

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      patrik08
                      wrote on last edited by patrik08
                      #53

                      Image debug is not simple... but Base64 is a nice way..
                      i hope to render you idea...
                      source on https://github.com/pehohlva/QOASIS/blob/master/test/dkernel/sys/core_htmldriver.cpp
                      to display RTFD documents + image from mac.
                      by patrik

                      /*   image to html display whitout image link & play in qt4/qt5 */ 
                      QByteArray HtmlDriver::pic_encode( QImage im )  {
                          int w=im.width();
                          int h=im.height();
                          QByteArray bytes;
                         //// scale if to big
                          if (w > 550 ) {
                              im.scaled(550,550, Qt::KeepAspectRatio);
                          }
                          QBuffer buffer(&bytes);
                          buffer.open(QIODevice::WriteOnly);
                          im.save(&buffer, "PNG");
                         /// save inside buffer ram
                          if (bytes.size() > 0) {
                          QByteArray blueimag = bytes.toBase64();
                          QByteArray orderpic("data:image/png;base64,");
                          orderpic.append(blueimag);
                          return orderpic;
                         /// and insert inside image src=
                          } else {
                            /// if image is brocken 1x1 pixel transparent...  but 95% image pass.
                              return QByteArray("data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==");
                          }
                      }
                      
                      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