在Windows(Vista)上使用C ++和Qt进行GUI设计的问题 [英] GUI design issues using C++ , Qt on Windows (Vista)

查看:123
本文介绍了在Windows(Vista)上使用C ++和Qt进行GUI设计的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这涉及C ++(MinGW),Qt,Windows Vista:

在我用C ++开发非GUI应用程序时,所有这一切.最近,我决定在Qt中尝试使用GUI并遇到一些设计问题.

这是问题所在:

  • 步骤1:使用QMovie加载并显示背景gif动画...
  • 第2步:处理巨大的转储文件(超过2GB)....因此,当我到达第2步时,我的GUI冻结了..

我正在使用 while(getline(inputFileStream,stringLine)){...} ,所以我将 QCoreApplication :: processEvents(); 放入了循环.

应用程序变得非常缓慢.因此,我放置了一个计数器,该计数器只有在达到特定值时才会执行 QCoreApplication :: processEvents(); .

现在,gif动画已变得更像一系列帧,可见的帧从一个过渡到另一个.

processEvents()的任何更快的触发都会减慢应用程序的速度(无论如何,它离非GUI执行时间都不远).

正如我从Windows Task Manager中看到的那样,在执行期间,一个内核的利用率很高,而另一个内核的利用率却很低.

那我应该采取什么方法?我应该深入研究多线程(我以前从未使用过)吗?

精简所有内容以解释程序如下所示的问题:

class Animation; 
class FileProcessing;

main(int argc,char** argv) {
        QApplication* app=new QApplication(argc,argv);
        QLabel* label1=new QLabel(...);
        QLabel* label2=new QLabel(...);
        Animation* objAnim=new Animation(...); //QMovie plays gif
        objAnim->show();

        //fileDialogs --> ask for files..this is modal so animation is fine till this point

        FileProcessing* objFileProcessing=new FileProcessing(...);

        objFileProcessing->processFiles(label1,label2); //process >2GB files
        //in this i repeatedly call processEvents() as written above

        //delete labels,objAnim and objFileProcessing;
        delete app;
        return 0;
}

解决方案

是时候该种一些球并学习如何使用线程了. GUI冻结是因为它在与处理那些大文件的功能相同的线程中运行.如果将这些任务分开以在不同线程中执行,则GUI可以继续可用.

由于您对Qt感兴趣,因此建议阅读有关 QThread QThread :

This concerns C++ (MinGW), Qt, Windows Vista:

all this while i's developing non-GUI applications in C++. Recently i decided to try a GUI one in Qt and am having some design issues.

Here's the problem:

  • step 1: Load and display a background gif Animation using QMovie...
  • step 2: process huge dump files (over 2GB's)....so when i reached step 2 expectedly my GUI froze..

i was using while(getline(inputFileStream,stringLine)) {...} so i placed QCoreApplication::processEvents(); inside the loop.

The application became really slow. So i placed a counter which only if it reaches a particular value will QCoreApplication::processEvents(); be executed.

Now the gif animation has become more like series of frames with visible transition from one to another.

Any faster triggering of processEvents() slows the application down (which anyway is nowhere near the non-GUI execution time).

As i see from Windows Task Manager one core has high utilization while other has low during the execution period.

So what approach should i take? Should i delve into mutithreading (i'v never used it before)?

Stripping down everything to explain the question the program looks like this:

class Animation; 
class FileProcessing;

main(int argc,char** argv) {
        QApplication* app=new QApplication(argc,argv);
        QLabel* label1=new QLabel(...);
        QLabel* label2=new QLabel(...);
        Animation* objAnim=new Animation(...); //QMovie plays gif
        objAnim->show();

        //fileDialogs --> ask for files..this is modal so animation is fine till this point

        FileProcessing* objFileProcessing=new FileProcessing(...);

        objFileProcessing->processFiles(label1,label2); //process >2GB files
        //in this i repeatedly call processEvents() as written above

        //delete labels,objAnim and objFileProcessing;
        delete app;
        return 0;
}

解决方案

It's time for you to grow some balls and learn how to use threads. The GUI freezes because it runs within the same thread as the functions that deal with those large files. If you separate these tasks to be executed in different threads, the GUI can continue to be useable.

Since you have an interested in Qt, I suggest reading about QThread:

这篇关于在Windows(Vista)上使用C ++和Qt进行GUI设计的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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