How to save a session in a Qt application? - c++

I made this tool in Qt Creator where i have to enter some data in spin boxes and combo boxes. Each of these boxes have a default value when I open my tool. But I would like to implement a function to save the session of the application, i.e. if i modify some values in the boxes i can save them and when I open my application again my modifications are there. And also when I am done with that data I can restore the defaults.
Any idea as to how to do this?

Use QSettings , it's usage is explained in the page

Related

How can I save Checkbox selection in qt c++?

I am trying to develop an application with QT C++. I added a checkBox. How can I make my checkBox be in the last selection when I close my app and open it again. For example, if the checkbox was selected before the application was closed, I want it to be selected when the application runs again. If it wasn't selected before closing, it should come back unselected when it runs again. How can I do that?
Read the value of the checkbox when your app shuts down. Save the value somewhere, like; QSettings, a custom file, windows registry, etc. When your application starts, read the stored value and set the checkbox state to match.

Displaying image using CDialog::CreateIndirect

I'm modifying MFC C++ code that previews dialogs from Win32 apps when they are being localised/internationalised. One of the limitations of our current approach is that we can't display images from an app being localised, we just insert a placeholder image.
What I would like is a way to enhance this functionality to display an image loaded externally from another app into a child dialog that I create myself.
We preview a dialog from a given Win32 program and recreate the dialogs plus any changes translators have made, using the CDialog::CreateIndirect function.
In effect, we are recreating the original dialog from the Win32 app as a child window of our software.
CDialog::CreateIndirect takes a DLGTEMPLATE structure as an argument which contains all of the data needed to reconstruct a dialog. It's here that we insert the resource id of our placeholder image.
I have searched to see is there are way to write the raw binary data of the image I want to display, or else dynamically add the image into my own app's list of resource IDs so I can use it that way, but ours seems to be an obscure use case.
Any help or advice would be appreciated, thanks.

Setting AdvancedPrintingOptions from C++ code

I'm working with my friend to create a simple Photo Booth device. We are using DNP RX1 Printer, and this printer has the ability to cut photos in half.
When printing photos directly from windows cutting can be set as Enabled/Disabled via "Advanced Options" window in Printer Properties.
How to Enable/Disable Cut (2inch cut)
I'm working on application for this Photo Booth device (Developed on Windows 7). I'm using C++ and Qt as my GUI framework. There is a QPrintSupport module in Qt library that can be used to print images from my application, and I know how to do it. But the problem is that there is no way to Enable/Disable this "cut photos in half" option using Qt library. It is possible to display settings window to user using QPrintDialog class, but I want the process of taking photo and printing to be automatic ( User only press start button, smiles and waits till photo comes out). My workaround for this problem was to save files to two folders, and use different program to print photos from the first folder with cut option enabled and from the other folder with cut option disabled. But the problem was that printer was sometimes detected as DS-RX1 and sometimes as "DS-RX1 (Copy)" or even "DS-RX1 Copy 1", then this solution didn't work and someone had to manually delete printer from the system and reconnect it.
My question is: Is there a way to print a photo from C++ program using default printer and change this Advanced Printer Option (2inch cut) from C++ code? OR: Is there a way to force this printer to be detected always as DS-RX1?
Maybe you can set priner by substring "DS-RX1".
You can get list of available printers http://doc.qt.io/qt-5/qprinterinfo.html#availablePrinters by substring and as a variant you can set printer by setPrinterName function http://doc.qt.io/qt-5/qprinter.html#setPrinterName

Save load in gui application

I try to make custom savefile for my GUI application.
In saving method I have something like this to save enabled status of all checkboxes.
enabledparams = [checkbox.isEnabled() for checkbox in self.tabParameters.findChildren(QtGui.QCheckBox)]
In loading method I should do this in backward sense, so to make enabled status from the saved
enabledparams
How to do this effectively in pythonic sense with minimum of code?
I have more of these cases for checked state of the boxes and also for a lot of spinboxes and textboxes.
Thank you in advance
the QSettings module of Qt would be useful to you. It provides functionality to save and load application settings.

QT4 qlistview save icon position moved by hand for the next time

I'm developing an app with qt4.3 which opens a window with a bunch of icons loaded from .desktop files. It tries to emulate a file browser but without file browsing... I mean, you can double click and open an app or drag the icons to an other position not necessary attached to the grid.
I'm using a qdirmodel and a qlistview in "icon mode".
My problem is that I can't save the position of the icons once I moved them. Every time I restart the app, I get the icons loaded in the default position.
I can't find any way to know the position of an item or move an item to a position.
What I should do? Do I have any chance?
Thanks!
I'm sure, you can save item's position. You should read about save session qt.
This is official qt doc about Session Management Session Management
And also I'll advice to read qt's possibility save settings QSettings
After looking at the qlistview code I found that I can also inherit the qlistview class and convert to public a couple of protected functions which return the item position and move the item to a position. Thanks anyway!!