Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How set source for Image - function on c++
Forum Updated to NodeBB v4.3 + New Features

How set source for Image - function on c++

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 4 Posters 631 Views 1 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.
  • M Offline
    M Offline
    Mihaill
    wrote on 22 Nov 2019, 10:53 last edited by aha_1980
    #1

    Hi!
    I have function on c++, this function return QImage.
    How I can set source for Image - this function?

    S 1 Reply Last reply 23 Nov 2019, 03:59
    0
    • V Offline
      V Offline
      VRonin
      wrote on 22 Nov 2019, 10:55 last edited by
      #2

      https://doc.qt.io/qt-5/qimage.html#load

      "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 22 Nov 2019, 11:26
      2
      • V VRonin
        22 Nov 2019, 10:55

        https://doc.qt.io/qt-5/qimage.html#load

        M Offline
        M Offline
        Mihaill
        wrote on 22 Nov 2019, 11:26 last edited by
        #3

        @VRonin Why do that? My function creates and returns QImage on its own.
        How to set the returned QImage for Image in qml?

        1 Reply Last reply
        0
        • I Offline
          I Offline
          IntruderExcluder
          wrote on 22 Nov 2019, 12:27 last edited by
          #4

          For not large images you can convert them to a string using Base64 format. Not optimal but kind of acceptable. For large images it is better to use QQuickImageProvider.

          1 Reply Last reply
          3
          • M Offline
            M Offline
            Mihaill
            wrote on 22 Nov 2019, 13:11 last edited by Mihaill
            #5

            I use this code, but Image in qml not use thes string.
            How fix this?

                QString resultString;
                QByteArray ba;
                QBuffer bu(&ba);
                bu.open(QIODevice::WriteOnly);
                image.save(&bu, "PNG");
                resultString = QString::fromLatin1(ba.toBase64().data());
                qDebug()<<"resultString = QString::fromLatin1"<<resultString;
                return resultString;
            

            And this too not work

            resultString = ba.toBase64();
            
            1 Reply Last reply
            0
            • M Offline
              M Offline
              Mihaill
              wrote on 22 Nov 2019, 13:41 last edited by
              #6

              It is work

                  QString resultString;
                  QByteArray ba;
                  QBuffer bu(&ba);
                  bu.open(QIODevice::WriteOnly);
                  image.save(&bu, "PNG");
                  //resultString = QString::fromLatin1(ba.toBase64().data());
                  resultString = QString::fromLatin1("data:image/png;base64,") + QString::fromLatin1(ba.toBase64().data());
                  qDebug()<<"resultString = QString::fromLatin1"<<resultString;
                  return resultString;
              
              1 Reply Last reply
              0
              • M Mihaill
                22 Nov 2019, 10:53

                Hi!
                I have function on c++, this function return QImage.
                How I can set source for Image - this function?

                S Offline
                S Offline
                small_bird
                wrote on 23 Nov 2019, 03:59 last edited by
                #7

                @Mihaill using image provider class, the qt example shows it.

                1 Reply Last reply
                0

                1/7

                22 Nov 2019, 10:53

                • Login

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