向Qt项目添加状态对话框 [英] Add status dialog to Qt project

查看:235
本文介绍了向Qt项目添加状态对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使开源文件管理器能够根据给定的密码Cryptofm加密和解密文件.您可以从此处(第一个版本)获取代码.我要添加状态对话框,以进度栏达到最大值以关闭statusdialog后,显示带有Dialog::encAll()插槽进度栏的加载屏幕.我发现我必须首先以递归方式找到文件夹中所有文件的总大小(在TreeView上下文菜单选项大小"中)-插槽Dialog::dirSize()借助功能Dialog::getSelectedTreeItemSize()来执行此操作,然后设置进度条属性最大为该值.总大小计算过程可能又要花费很多时间,因此我需要另一个对话框进行一些操作,以表明进程正在执行.整个过程应该类似于在Windows 7中粘贴带有很多文件的非常大的文件夹的过程.

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 pasteing untill progress bar reach the total size:

问题是几乎所有函数,动作等都在Dialog类中实现,并且我无法使用线程-在dialog.h中添加像这样的Dialog : public QDialog, public QThread的QThread后(能够实现run()方法),该程序给出了一些错误:

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:错误:C2594: 'argument':从'Dialog * const'到'QObject的模棱两可的转换 *'

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:错误:C2594: 'argument':从'Dialog * const'到'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:错误:C2385: 连接"的歧义访问可能是基本"QObject"中的连接" 或者可以是基础"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'

还有另外31个错误,所以:

And another 31 errors, so:

  • 这里最好的选择是什么?
  • 我应该使用MVC还是其他模式?
  • 我应该使用线程吗?

推荐答案

我做了一些事情.这看起来并不容易.我已经在名为threadedController的新类中分离了所有执行代码,并通过moveToThread将其在mainWindow中移动到了新线程中.重要的是要注意,该类继承了QObject以便能够使用信号插槽机制,它在构造函数中没有父级,因为在其他情况下,它无法移动到新线程中. QWidget对象无法在新线程中移动.看起来,GUI线程和新线程之间的通信可以通过信号槽机制实现. Qt正在使用模型/视图架构.每个人都可以从此处下载第二版本的源代码和exe.

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.

这篇关于向Qt项目添加状态对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆