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 to Send QML image to C++ side
Forum Updated to NodeBB v4.3 + New Features

How to Send QML image to C++ side

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 746 Views 2 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.
  • I Offline
    I Offline
    isan
    wrote on last edited by
    #1

    I want to send the image from qml to c++ to be stored in the SQL database
    This is my code, but when I click the save button, my program crashes
    How can I fix it?

    c++ side:

    void ImageProvider::saveToDatabase(QObject *imageObj) {
    QQuickItemGrabResult *item = nullptr;
      item = qobject_cast<QQuickItemGrabResult *>(imageObj);
      QImage img(item->image());
      QByteArray imageArray;
      QBuffer buffer(&imageArray);
      buffer.open(QIODevice::WriteOnly);
      img.save(&buffer, "PNG");
     dbModify->dbinsertRecords(imageArray);
    }
    

    qml side:

    Page {
      property alias url: screenshoot.source //set source from another place
     Image {
             id: screenshoot
             }
     Button {
                id: button
                onClicked: {
                    imgProvider.saveToDatabase(screenshoot)
                }
            }
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      Are you trying to implement something like described here ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      I 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        You don't check that item is a valid pointer.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        I 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          You don't check that item is a valid pointer.

          I Offline
          I Offline
          isan
          wrote on last edited by
          #3

          @SGaist said in How to Send QML image to C++ side:

          item is a valid pointer

          You mean this?

          void ImageProvider::saveToDatabase(QObject *imageObj) {
           QQuickItemGrabResult *item = nullptr;
            item = qobject_cast<QQuickItemGrabResult *>(imageObj);
            if (item) {
              QImage img(item->image());
            QByteArray imageArray;
            QBuffer buffer(&imageArray);
            buffer.open(QIODevice::WriteOnly);
            img.save(&buffer, "PNG");
           dbModify->dbinsertRecords(imageArray);
              }
          }
          

          The program does not crash, but nothing is stored in the database, the way that I send image to c++ is true?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Are you trying to implement something like described here ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            I 1 Reply Last reply
            0
            • SGaistS SGaist

              Are you trying to implement something like described here ?

              I Offline
              I Offline
              isan
              wrote on last edited by
              #5
              This post is deleted!
              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