Save labels( Pixmap) and CSV table information on same file, then Load back
-
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 !! -
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. -
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.@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.
-
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.
-
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.
@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!
-
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.
-
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.
@SGaist No, image folder and contents need to be controlled by the user.
-
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(); }