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. Load Image From Db Problem
QtWS25 Last Chance

Load Image From Db Problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
loading imagesdatabaseproblem
26 Posts 4 Posters 11.9k 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 mrjj
    24 Aug 2016, 21:32

    @M4RZB4Ni said:

    well ,start with looking at some return codes.

    qDebug() << "exec:" << readSkeletonPicQry.exec(xx)
    qDebug() << "outByteArray :" << outByteArray.size();

    is seMcode a string?

    M Offline
    M Offline
    M4RZB4Ni
    wrote on 24 Aug 2016, 21:37 last edited by
    #3

    @mrjj
    ok i will do it
    yes seMcode is String and for other data selection like username and etc Worked

    Thanks
    M4RZB4Ni

    M 1 Reply Last reply 24 Aug 2016, 21:40
    0
    • M mrjj
      24 Aug 2016, 21:32

      @M4RZB4Ni said:

      well ,start with looking at some return codes.

      qDebug() << "exec:" << readSkeletonPicQry.exec(xx)
      qDebug() << "outByteArray :" << outByteArray.size();

      is seMcode a string?

      M Offline
      M Offline
      M4RZB4Ni
      wrote on 24 Aug 2016, 21:40 last edited by
      #4

      @mrjj
      exec: Unable to execute statement: "[Microsoft][ODBC Driver Manager] Function sequence error"
      false
      outByteArray : 0
      what i should do?

      Thanks
      M4RZB4Ni

      1 Reply Last reply
      0
      • M M4RZB4Ni
        24 Aug 2016, 21:37

        @mrjj
        ok i will do it
        yes seMcode is String and for other data selection like username and etc Worked

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 24 Aug 2016, 21:40 last edited by
        #5

        @M4RZB4Ni said:

        loadFromData

        also check return from that :)

        M 1 Reply Last reply 25 Aug 2016, 04:01
        0
        • M mrjj
          24 Aug 2016, 21:40

          @M4RZB4Ni said:

          loadFromData

          also check return from that :)

          M Offline
          M Offline
          M4RZB4Ni
          wrote on 25 Aug 2016, 04:01 last edited by
          #6

          @mrjj
          its seems Query is not Execute Properly

          Thanks
          M4RZB4Ni

          1 Reply Last reply
          0
          • M Offline
            M Offline
            M4RZB4Ni
            wrote on 25 Aug 2016, 10:02 last edited by
            #7

            Any Body Cant Help me?

            Thanks
            M4RZB4Ni

            M 1 Reply Last reply 25 Aug 2016, 10:06
            0
            • M M4RZB4Ni
              25 Aug 2016, 10:02

              Any Body Cant Help me?

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 25 Aug 2016, 10:06 last edited by mrjj
              #8

              @M4RZB4Ni
              Hi
              Its impossible to guess why
              "SELECT SskeletonPic FROM Patient_File WHERE SmeliCode='"+seMcode+"'"
              is not correct.
              Could be non existing seMcode
              Anyway, you MUST use correct error handling to have a fighting chance
              so please add error checking.

              as in

              QSqlQuery query;
              query.exec(QString("select NAME from PEOPLE where AGE=%1").arg(age));
              if (query.next())
              {
              qDebug() << "query ok:";
              } else {
                  qDebug() << "SqLite error:" << query.lastError().text() << ", error code:" << query.lastError().number();
              }
              
              M 1 Reply Last reply 25 Aug 2016, 10:18
              0
              • M mrjj
                25 Aug 2016, 10:06

                @M4RZB4Ni
                Hi
                Its impossible to guess why
                "SELECT SskeletonPic FROM Patient_File WHERE SmeliCode='"+seMcode+"'"
                is not correct.
                Could be non existing seMcode
                Anyway, you MUST use correct error handling to have a fighting chance
                so please add error checking.

                as in

                QSqlQuery query;
                query.exec(QString("select NAME from PEOPLE where AGE=%1").arg(age));
                if (query.next())
                {
                qDebug() << "query ok:";
                } else {
                    qDebug() << "SqLite error:" << query.lastError().text() << ", error code:" << query.lastError().number();
                }
                
                M Offline
                M Offline
                M4RZB4Ni
                wrote on 25 Aug 2016, 10:18 last edited by
                #9

                @mrjj
                no!
                seMcode is true because i can select more data with it !
                i think problem is converting from table(IMAGE DATATYPE) TO byte array !
                and i write your qdebug code and says query ok!

                Thanks
                M4RZB4Ni

                M V 2 Replies Last reply 25 Aug 2016, 10:23
                0
                • M M4RZB4Ni
                  25 Aug 2016, 10:18

                  @mrjj
                  no!
                  seMcode is true because i can select more data with it !
                  i think problem is converting from table(IMAGE DATATYPE) TO byte array !
                  and i write your qdebug code and says query ok!

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 25 Aug 2016, 10:23 last edited by
                  #10

                  @M4RZB4Ni
                  well check return code from loadFromData to know if it fails.
                  and the size of QBytearray

                  M 1 Reply Last reply 25 Aug 2016, 10:43
                  0
                  • M mrjj
                    25 Aug 2016, 10:23

                    @M4RZB4Ni
                    well check return code from loadFromData to know if it fails.
                    and the size of QBytearray

                    M Offline
                    M Offline
                    M4RZB4Ni
                    wrote on 25 Aug 2016, 10:43 last edited by
                    #11

                    @mrjj
                    According to qDebug Report

                    outByteArray : 8
                    QODBCResult::exec: Unable to execute statement: "[Microsoft][ODBC Driver Manager] Function sequence error"
                    false
                    

                    Byte array size is 8

                    Thanks
                    M4RZB4Ni

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 25 Aug 2016, 10:59 last edited by mrjj
                      #12

                      Ok so it seems it dont like your BLOB
                      8 is not much for image so I wonder
                      if it saved more than 8 and just the reading that failed.

                      Anyway, its seems not to be Qt related as such so you should find out what
                      ODBC + "Function sequence error" means.

                      https://social.msdn.microsoft.com/Forums/sqlserver/en-US/86fc9d29-99ee-416e-891f-2451c4f09f4d/microsoftodbc-driver-manager-function-sequence-error-in-64bit-windows-2008-server?forum=sqldataaccess

                      but there are many others.

                      1 Reply Last reply
                      0
                      • M M4RZB4Ni
                        25 Aug 2016, 10:18

                        @mrjj
                        no!
                        seMcode is true because i can select more data with it !
                        i think problem is converting from table(IMAGE DATATYPE) TO byte array !
                        and i write your qdebug code and says query ok!

                        V Offline
                        V Offline
                        VRonin
                        wrote on 25 Aug 2016, 12:12 last edited by
                        #13

                        @M4RZB4Ni said in Load Image From Db Problem:

                        i think problem is converting from table(IMAGE DATATYPE) TO byte array !

                        are you using image as field type in your database? if so you shouldn't, it's deprecated and will be removed (see https://msdn.microsoft.com/en-us/library/ms187993.aspx). use varbinary(max) instead.

                        Also, you should use QImage instead of QPixmap.

                        Qt provides four classes for handling image data: QImage, QPixmap, QBitmap and QPicture. QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen. QBitmap is only a convenience class that inherits QPixmap, ensuring a depth of 1. Finally, the QPicture class is a paint device that records and replays QPainter commands.

                        "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

                        M 1 Reply Last reply 25 Aug 2016, 12:34
                        1
                        • V VRonin
                          25 Aug 2016, 12:12

                          @M4RZB4Ni said in Load Image From Db Problem:

                          i think problem is converting from table(IMAGE DATATYPE) TO byte array !

                          are you using image as field type in your database? if so you shouldn't, it's deprecated and will be removed (see https://msdn.microsoft.com/en-us/library/ms187993.aspx). use varbinary(max) instead.

                          Also, you should use QImage instead of QPixmap.

                          Qt provides four classes for handling image data: QImage, QPixmap, QBitmap and QPicture. QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen. QBitmap is only a convenience class that inherits QPixmap, ensuring a depth of 1. Finally, the QPicture class is a paint device that records and replays QPainter commands.

                          M Offline
                          M Offline
                          M4RZB4Ni
                          wrote on 25 Aug 2016, 12:34 last edited by
                          #14

                          @VRonin
                          yes i use IMAGE because when i use VABBINARY(MAX) when i want save image
                          program show error
                          "Cant Convert varchar datatype to VARBINARY(MAX)!
                          and i should Use IMAGE datatype!

                          Thanks
                          M4RZB4Ni

                          1 Reply Last reply
                          0
                          • V Offline
                            V Offline
                            VRonin
                            wrote on 25 Aug 2016, 12:55 last edited by VRonin
                            #15

                            How do you save it?

                            You should definitely use VARBINARY:

                            From Microsoft, page linked above:

                            IMPORTANT! ntext, text, and image data types will be removed in a future version of SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.

                            "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

                            1 Reply Last reply
                            0
                            • M M4RZB4Ni
                              24 Aug 2016, 20:39

                              Hi
                              I have saved a pic to my Sql Server Db
                              but When i want To load it in my Graphic View
                              DO nothing :|
                              this is my code:
                              .h file

                                      QPixmap originalPixmap;
                                      QPixmap outPixmap;
                                      QByteArray inByteArraye;
                                      QByteArray outByteArray;
                              

                              .cpp file

                                  readSkeletonPicQry.exec("SELECT SskeletonPic FROM Patient_File WHERE SmeliCode='"+seMcode+"'");
                                  outByteArray = readSkeletonPicQry.value(0).toByteArray();
                                  outPixmap = QPixmap();
                                  outPixmap.loadFromData(outByteArray,"PNG");
                                  scene->addPixmap(outPixmap);
                                  ui->graphicsView_2->setScene(scene)
                              

                              my datatype in sql server Table in IMAGE and its store pics Fine
                              but i cant Show pic in graphic View From Table
                              *My Table Pic
                              whats Wrong?

                              M Offline
                              M Offline
                              M4RZB4Ni
                              wrote on 25 Aug 2016, 13:13 last edited by M4RZB4Ni
                              #16

                              @M4RZB4Ni
                              this is all of my codes:
                              see it and if you can correct it
                              .h file:

                              QImage *pix;
                                      QImage originalPixmap;
                                      QPixmap outPixmap;
                                      QPixmap pxp;
                                      QGraphicsPixmapItem pixItem;
                                      QByteArray inByteArraye;
                                      QByteArray outByteArray;
                              

                              .cpp file:

                              void Medical_Records::shootScreen()
                              {
                                  QScreen *screen = QGuiApplication::primaryScreen();
                                  if (const QWindow *window = windowHandle())
                                      screen = window->screen();
                                  if (!screen)
                                      return;
                              
                                originalPixmap=ui->graphicsView_2->grab().toImage();
                                  updateGraphicView();
                              
                              }
                              void Medical_Records::initalizeVarables()
                              {
                                       shootScreen();
                                      QBuffer inBuffer( &inByteArraye );
                                      inBuffer.open(QIODevice::WriteOnly);
                                      originalPixmap.save(&inBuffer,"PNG");
                              }
                              
                              
                              void Medical_Records::readSkeletonPic()
                              {
                                  moveToThread(readSkeletonPicThread);
                                readSkeletonPicQry.exec("SELECT SskeletonPic FROM Patient_File WHERE SmeliCode='"+seMcode+"'");
                                  readSkeletonPicQry.next();
                                  outByteArray = readSkeletonPicQry.value(0).toByteArray();
                                  //outPixmap = QPixmap();
                                  originalPixmap.loadFromData(outByteArray,"PNG");
                                  qDebug() << "outByteArray :" << outByteArray.size();
                                  qDebug() << "outByteArray :" << originalPixmap.size();
                                  outPixmap.fromImage(originalPixmap.fromData(outByteArray,"PNG"));
                                  scene->addPixmap(outPixmap);
                                  ui->graphicsView_2->setScene(scene);
                                  qDebug() << readSkeletonPicQry.exec();
                                  readSkeletonPicThread->start();
                              }
                              

                              Thanks
                              M4RZB4Ni

                              1 Reply Last reply
                              0
                              • V Offline
                                V Offline
                                VRonin
                                wrote on 25 Aug 2016, 13:20 last edited by
                                #17

                                i don't get the threading thing but it's probably not the point here. where did you get the
                                "Cant Convert varchar datatype to VARBINARY(MAX)" error?

                                "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

                                M 1 Reply Last reply 25 Aug 2016, 13:24
                                0
                                • V VRonin
                                  25 Aug 2016, 13:20

                                  i don't get the threading thing but it's probably not the point here. where did you get the
                                  "Cant Convert varchar datatype to VARBINARY(MAX)" error?

                                  M Offline
                                  M Offline
                                  M4RZB4Ni
                                  wrote on 25 Aug 2016, 13:24 last edited by
                                  #18

                                  @VRonin
                                  when i want insert image into database after capture screenshot

                                  Thanks
                                  M4RZB4Ni

                                  1 Reply Last reply
                                  0
                                  • V Offline
                                    V Offline
                                    VRonin
                                    wrote on 25 Aug 2016, 13:59 last edited by
                                    #19

                                    Can you post that code please?

                                    "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

                                    M 1 Reply Last reply 25 Aug 2016, 14:07
                                    0
                                    • V VRonin
                                      25 Aug 2016, 13:59

                                      Can you post that code please?

                                      M Offline
                                      M Offline
                                      M4RZB4Ni
                                      wrote on 25 Aug 2016, 14:07 last edited by
                                      #20

                                      @VRonin
                                      yes of course
                                      thanks so much

                                      this is code :

                                      void Medical_Records::initalizeVarables()
                                      {
                                      
                                              shootScreen();
                                              QBuffer inBuffer( &inByteArraye );
                                              inBuffer.open(QIODevice::WriteOnly);
                                              originalPixmap.save(&inBuffer,"PNG");
                                      }
                                      void Medical_Records::submitWithScreenShot()
                                      {
                                      
                                        initalizeVarables();
                                          QSqlQuery sql;
                                          sql.exec("UPDATE Patient_File SET SskeletonPic='"+inByteArraye+"' WHERE SmeliCode='"+seMcode+"';");
                                      }
                                      

                                      Thanks
                                      M4RZB4Ni

                                      1 Reply Last reply
                                      0
                                      • V Offline
                                        V Offline
                                        VRonin
                                        wrote on 25 Aug 2016, 16:49 last edited by VRonin
                                        #21

                                        yep, you should check QSqlQuery::bindValue

                                        sql.prepare("UPDATE Patient_File SET SskeletonPic= :skp  WHERE SmeliCode= :smc");
                                        sql.bindValue(":skp",inByteArraye);
                                        sql.bindValue(":smc",seMcode);
                                        sql.exec();
                                        

                                        this also prevents SQL Injection. You should never really use unescaped input directly to build the query string

                                        "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

                                        M 1 Reply Last reply 25 Aug 2016, 16:57
                                        1
                                        • V VRonin
                                          25 Aug 2016, 16:49

                                          yep, you should check QSqlQuery::bindValue

                                          sql.prepare("UPDATE Patient_File SET SskeletonPic= :skp  WHERE SmeliCode= :smc");
                                          sql.bindValue(":skp",inByteArraye);
                                          sql.bindValue(":smc",seMcode);
                                          sql.exec();
                                          

                                          this also prevents SQL Injection. You should never really use unescaped input directly to build the query string

                                          M Offline
                                          M Offline
                                          M4RZB4Ni
                                          wrote on 25 Aug 2016, 16:57 last edited by
                                          #22

                                          @VRonin
                                          thanks but my problem is in Load image not save it!
                                          Thank a lot My Friend :)

                                          Thanks
                                          M4RZB4Ni

                                          1 Reply Last reply
                                          0

                                          12/26

                                          25 Aug 2016, 10:59

                                          • Login

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