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 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?

    small_birdS 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on 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
      2
      • VRoninV VRonin

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

        M Offline
        M Offline
        Mihaill
        wrote on 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
        • IntruderExcluderI Offline
          IntruderExcluderI Offline
          IntruderExcluder
          wrote on 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 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 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

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

                small_birdS Offline
                small_birdS Offline
                small_bird
                wrote on last edited by
                #7

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

                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