Details
-
Suggestion
-
Resolution: Fixed
-
Not Evaluated
-
None
-
6.6.1
-
None
Description
Hello, All!
I have already written about this, but the topic has been closed and they do not want to talk to me further, due to binary incompatibility and possibly some more.
There is no binary incompatibility anymore! I will describe QStorage again.
https://github.com/Navadvipa-Chandra-das/PrabhupadaDictionaryQt
QStorage is able to remember the most important settings of any QObject successor object and then restore these values at any time. To remember, you just need to call a function, for example:
AStorage.SaveObject( PrabhupadaLoginWindow, QStorageKind::File );
And to recover data, for example:
AStorage.LoadObject( PrabhupadaLoginWindow, QStorageKind::File );
See, it's very simple. To remember in memory, you need to use QStorageKind::Memory, and to remember in the database, you need to use the value of QStorageKind::DB ! Everything is very simple. In order for an object to have such an ability to remember and restore, you need to implement two public slots in the class, for example:
public slots: void LoadFromStream( QDataStream &ST ); void SaveToStream( QDataStream &ST ); void QPrabhupadaLoginDialog::LoadFromStream( QDataStream &ST ) { inherited::LoadFromStream( ST ); // 1 QStorage::LoadFromStream( m_ui->ComboBoxUserName, ST ); // 2 QStorage::LoadFromStream( m_ui->ComboBoxDatabaseName, ST ); // 3 QStorage::LoadFromStream( m_ui->ComboBoxHostName, ST ); // 4 QStorage::LoadFromStream( m_ui->ComboBoxPort, ST ); // 5 QStorage::LoadFromStream( m_ui->ComboBoxSchema, ST ); // 6 bool B; ST >> B; if ( B ) { m_ui->radioButtonSQLite->setChecked( true ); } else { m_ui->radioButtonPostgreSQL->setChecked( true ); } } void QPrabhupadaLoginDialog::SaveToStream( QDataStream &ST ) { inherited::SaveToStream( ST ); // 1 QStorage::SaveToStream( m_ui->ComboBoxUserName, ST ); // 2 QStorage::SaveToStream( m_ui->ComboBoxDatabaseName, ST ); // 3 QStorage::SaveToStream( m_ui->ComboBoxHostName, ST ); // 4 QStorage::SaveToStream( m_ui->ComboBoxPort, ST ); // 5 QStorage::SaveToStream( m_ui->ComboBoxSchema, ST ); // 6 ST << m_ui->radioButtonSQLite->isChecked(); }
I took this example from my program. The position of the Dialog on the screen is saved and restored - this is provided by the calls inherited::LoadFromStream( ST) and inherited::SaveToStream( ST). But plus, the DisplayText() of several ComboBox and their drop-down lists are saved, which contain the history of user input values. The program has other examples of saving even more complex data structures! Here I want to add such a class to the Qt library!
In general, the QStorage class can work successfully without the need to define two slots (LoadFromStream and SaveToStream) in those classes that want to save and load their instances. It is not difficult to redo it to work with static QMap<type id, FunctionPointer>. Then it will be possible to save and load the most ordinary classes, such as QMainWindow, QLineEdit and any other standard Qt classes! Everything is very simple. You only need to fill this QMap with pointers to the LoadFromStream and SaveToStream functions for all the necessary classes at the beginning of the program execution.
The QStorage class is defined in the files QPrabhupada.h and QPrabhupada.cpp . I left a link to my repository above. It is publicly available. I started to get acquainted with Qt a couple of months ago more thoroughly, starting to write this program "Srila Prabhupada Dictionary". Shrila Prabhupada is the founder-acharya of the International Society for Krishna Consciousness - Shri Shrimad Abhai Charanaravinda Bhaktivedanta Swami Prabhupada! This program has not been completed yet and I am currently trying the MSVC compiler, and one error has appeared on it, which did not appear on the GCC 11.2 compiler. But the QStorage class itself works on both compilers. You can ignore the incompleteness of the program in this case!
My native language is not English, so it may be difficult for me to convey to you the essence of my message. I translate by Yandex translator. But I'm trying.
Thank you!
Now I have done that and the MSVC compiler can be used. At first, the program worked only on GCC.
With best regards, Navadvipa Chandra dasa.