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. Save labels( Pixmap) and CSV table information on same file, then Load back
QtWS25 Last Chance

Save labels( Pixmap) and CSV table information on same file, then Load back

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 671 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
    GARUCHIRAZUMAN
    wrote on last edited by
    #1

    Hello everybody.
    I just completed some courses on Udemy to work with Pixmaps and saving/loading table information on a CSV file. Now, I want to implement my knowledge on making a kind of application to display connector circuits testing sequence. For that Im using a Raspberry PI and 8 MCP23017 modules to expand GPIOs up to 128. I already made test using the Wiring Pi library on QT and works as a charm. Now I want to add more features to this application (display images, as currently it is only text being displayed) and for that I want to add Qlabels to display pixmaps (only way I know so far) containing the pictures of the connectors and right next to them this CSV table with the electrical testing sequence. I already did all this and worked as desired. The problem comes as I need to save then load the sequence with the pictures included on same file. As I only know how to do it separately (CSV or render scene to image only). Is there any way to save this table information and all the in scene pictures on same file? So later I can make more testing sequence programs (with their respective pictures and table information) and then just load and run as needed? I'm not adding any code as I already mentioned, everything works fine, just need to save/load my scene including the table information and all pictures on one single file. Thanks in advanced !! and have a great day !!

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

      Hi,

      Where does the image come from ?
      One way is to create a binary file and use QDataStream to load and store whatever you need from there.

      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
      1
      • SGaistS SGaist

        Hi,

        Where does the image come from ?
        One way is to create a binary file and use QDataStream to load and store whatever you need from there.

        G Offline
        G Offline
        GARUCHIRAZUMAN
        wrote on last edited by
        #3

        @SGaist Image comes from a folder located in the Desktop. I used the QPixmap and QGraphicsPixmapItem to add it to current scene. Thanks for the quick reply Sir.

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

          The next question is: how are you going to provide these pictures with your application ?

          Based on that, you can also simply store an ID for it that you will use to reload it rather than storing the full image.

          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
          1
          • SGaistS SGaist

            The next question is: how are you going to provide these pictures with your application ?

            Based on that, you can also simply store an ID for it that you will use to reload it rather than storing the full image.

            G Offline
            G Offline
            GARUCHIRAZUMAN
            wrote on last edited by
            #5

            @SGaist Well, I just want for final application to include a open/browse button. So user can click it and then a browse folder will open and then user just choose image file and click ok, image should appear on scene. Then user once finishes placing pictures, he/she will save current scene with everything (table and images) together in same file. So if I understand correctly, by assigning an Id you mean a file path? so user just types the ID or path of the file (image) and then it should appear on label when needed instead of browsing pictures and then place them? if so, can you please just provide a more detail on what functions, methods are needed to work with IDs or paths with images? Sorry if I ask too much, I'm still learning but I find this very passionate and challenging. Thank you!

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

              Will that folder and its content be under your control ?

              As for the ID, it can be whatever suits you as it is not something user facing.

              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
              0
              • SGaistS SGaist

                Will that folder and its content be under your control ?

                As for the ID, it can be whatever suits you as it is not something user facing.

                G Offline
                G Offline
                GARUCHIRAZUMAN
                wrote on last edited by
                #7

                @SGaist No, image folder and contents need to be controlled by the user.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  GARUCHIRAZUMAN
                  wrote on last edited by
                  #8

                  Well, Im changing to Solved, as @SGaist you are correct, best way was using a QDataStream to save and load data I used QByteArray and worked for me, but instead on saving internally I used a MYSQL database (localhost) to save pictures and works as a charm. Thanks for your time. here the code that worked for me: Hope it helps someone with the same issue.

                  void MainWindow::on_pushButton_save2SQL_clicked()
                  {
                      auto fileName = QFileDialog ::getOpenFileName(this,"Select Image","/home/pi/Pictures","Image Files (*.png *.jpg);;Any file (*.*)");
                  
                      if (fileName.isEmpty()) {
                          return;
                      } ui->nombreArchivoLineEdit->setText(fileName);
                      QFile file (fileName);
                      if (!file.open(QIODevice::ReadOnly)) return;
                  
                      QByteArray inbyteArray = file.readAll();
                      QSqlQuery query;
                      query.prepare("INSERT INTO try (image) VALUES (:imageData)");
                      query.bindValue(":imageData",inbyteArray);
                      query.exec();
                      mModel->select();
                  }
                  
                  1 Reply Last reply
                  1

                  • Login

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