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

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.
  • 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
              • V Offline
                V Offline
                VRonin
                wrote on 25 Aug 2016, 16:58 last edited by VRonin
                #23

                make the field varbinary(max), save it that way and the code you have will work, no changes needed on the load part

                image in SQL server is a fixed length string. it has nothing to do with images

                "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
                4
                • K Offline
                  K Offline
                  Kutyus
                  wrote on 21 Jun 2017, 14:48 last edited by
                  #24

                  Hi!
                  The same problem, you could solve?
                  Thanks

                  V 1 Reply Last reply 21 Jun 2017, 15:20
                  0
                  • K Kutyus
                    21 Jun 2017, 14:48

                    Hi!
                    The same problem, you could solve?
                    Thanks

                    V Offline
                    V Offline
                    VRonin
                    wrote on 21 Jun 2017, 15:20 last edited by
                    #25

                    @Kutyus

                    Summary of the above:

                    • in the database use the type VABBINARY not IMAGE
                    • use QSqlQuery::bindValue instead of string concatenation to build your query

                    "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

                    K 1 Reply Last reply 22 Jun 2017, 06:00
                    3
                    • V VRonin
                      21 Jun 2017, 15:20

                      @Kutyus

                      Summary of the above:

                      • in the database use the type VABBINARY not IMAGE
                      • use QSqlQuery::bindValue instead of string concatenation to build your query
                      K Offline
                      K Offline
                      Kutyus
                      wrote on 22 Jun 2017, 06:00 last edited by
                      #26

                      @VRonin Thank you for reply, but my problem is the load image from database, please see my another question:
                      QT 5.8 image from database error

                      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