Search code examples
c++qtarchitectural-patterns

Add status dialog to Qt project


I am making open source file manager with the ability to encrypt and decrypt file/files according given password called Cryptofm. You can get the code from here - the first version. I want to add status dialog, representing loading screen with progress bar for Dialog::encAll() slot, after the progress bar reached max value to close the statusdialog. I found out that I must firstly recursively find the total size of all files in the folder(in TreeView context menu option Size) - slot Dialog::dirSize() is doing this with the help of the function Dialog::getSelectedTreeItemSize(), and then set the progress bar property maximum to that value. Total size calculation proccess may take again a lot of time so I need another dialog with something moving to just indicate the process is executing. The whole thing should be something like the process of pasting very large folder with a lot of files in Windows 7.

Process of getting the total size:

enter image description here

Process of pasteing untill progress bar reach the total size:

enter image description here

The problem is that almost all functions,actions and etc are implemented in the Dialog class and I am not able to use threads - after adding QThread like this Dialog : public QDialog, public QThread in dialog.h(to be able to implement run() method) the program gives some errors:

C:\Users\niki\Documents\EncryptionProject\dialog.cpp:41: error: C2594: 'argument' : ambiguous conversions from 'Dialog *const ' to 'QObject *'

C:\Users\niki\Documents\EncryptionProject\dialog.cpp:46: error: C2594: 'argument' : ambiguous conversions from 'Dialog *const ' to 'QObject *'

C:\Users\niki\Documents\EncryptionProject\dialog.cpp:51: error: C2385: ambiguous access of 'connect' could be the 'connect' in base 'QObject' or could be the 'connect' in base 'QObject'

And another 31 errors, so:

  • What are the best options here?
  • Should I use MVC or another pattern?
  • Should I use threads?

Solution

  • I done something. It is not that easy like it looks. I have separated all the execution code in new class called threadedController and with moveToThread moved it in mainWindow to new thread. It is important to notice that this class is inheriting QObject in order to be able to use signal-slot mechanism, it have no parent in the constructor, becouse in other case it could not be moved to new thread. QWidget objects cannot be moved in new thread. It seems the comunication between GUI thread and new thread is able to be made by signal-slot mechanism. Qt is using Model/View architecture. Everyone can download the second version source and exe from here.