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. Convert Qstring to QPixmap
QtWS25 Last Chance

Convert Qstring to QPixmap

Scheduled Pinned Locked Moved General and Desktop
qpixmapqstringqgraphicsitem
10 Posts 4 Posters 6.2k 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.
  • G Offline
    G Offline
    Gillou_beginqt
    wrote on 17 Aug 2015, 14:54 last edited by
    #1

    Hello,
    I am working on project where I have to display image saved in my database into different scene using QGraphicScene. The images are query in string but I am not able to display them in the different scene.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pmh4514
      wrote on 17 Aug 2015, 15:14 last edited by
      #2

      what have you tried already?
      You will not be "converting" a QString to QPixmap, rather, you have to drawText(..) to it.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Gillou_beginqt
        wrote on 17 Aug 2015, 15:18 last edited by
        #3

        I tried to used a qvariant variable to convert. But It's not working. Maybe the syntax was wrong
        Can you elaborate about drawText().

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 17 Aug 2015, 16:27 last edited by
          #4

          Hi,

          @pmh4514 @Gillou_beginqt means that he has full images saved in his database, not that he wants to draw text coming from his database.

          @Gillou_beginqt how did you save these images ? What format to they have ?

          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 17 Aug 2015, 16:34
          0
          • S SGaist
            17 Aug 2015, 16:27

            Hi,

            @pmh4514 @Gillou_beginqt means that he has full images saved in his database, not that he wants to draw text coming from his database.

            @Gillou_beginqt how did you save these images ? What format to they have ?

            G Offline
            G Offline
            Gillou_beginqt
            wrote on 17 Aug 2015, 16:34 last edited by
            #5

            @SGaist
            @@
            QFile file(fileName);
            if (!file.open(QIODevice::ReadOnly)) return;
            QString img_id,img_name;
            img_id=ui->imgId->text();
            int id=img_id.toInt();
            img_name=ui->imgName->text();
            QByteArray byteArray = file.readAll();

            QSqlQuery query;
            query.prepare("INSERT INTO images(image_id,image_name,images) VALUES (?,?,?)");

            query.addBindValue(id);
            query.addBindValue(img_name);
             query.addBindValue(byteArray);
            query.exec();
            

            @@
            This is the code I used to saved the images in my database. They are in QBytearray

            1 Reply Last reply
            0
            • C Offline
              C Offline
              c.savur
              wrote on 17 Aug 2015, 18:10 last edited by
              #6

              Hello,

              when you save the image to database, save as unsigned char and save size of the image then you can generate image by following :

              QImage(const uchar * data, int width, int height, Format format);

              then you can convert the QPixmap

              QPixmap pixmap = QPixmap::fromImage(img);

              After you have Qpixmap you can add to scene by using QGraphicsPixmapItem.

              Qimage Doc. t

              1 Reply Last reply
              1
              • G Offline
                G Offline
                Gillou_beginqt
                wrote on 17 Aug 2015, 19:07 last edited by
                #7

                How to save as unsigned char and save the size of the image

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 17 Aug 2015, 19:51 last edited by
                  #8

                  How are you constructing the image from 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

                  G 1 Reply Last reply 18 Aug 2015, 12:35
                  0
                  • S SGaist
                    17 Aug 2015, 19:51

                    How are you constructing the image from the database ?

                    G Offline
                    G Offline
                    Gillou_beginqt
                    wrote on 18 Aug 2015, 12:35 last edited by Gillou_beginqt
                    #9

                    @SGaist I was planning to use the code of the drill down example but I am not able to display the pictures from my database

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 18 Aug 2015, 21:31 last edited by
                      #10

                      Does the Drill Down Example work correctly for you ?

                      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
                      0

                      10/10

                      18 Aug 2015, 21:31

                      • Login

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