QT:如何一次打开多个窗口(QWidgets)? [英] QT: How to open several windows (QWidgets) at once?

查看:171
本文介绍了QT:如何一次打开多个窗口(QWidgets)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做 Web 界面测试程序,它应该同时在两个 webkit 窗口中打开两个 url.

I'm doing web interface testing program which should open two urls in two webkit windows simultaneously.

我已经为测试自动化编写了代码.

I already did the code for the test automation.

1) 用户按下Go"按钮,webkit (QWidget) 窗口打开

1) User pushes 'Go' button and webkit (QWidget) window opens

2) TestBot 类对象执行测试

2) TestBot class object performs tests

3) 关闭

现在我的问题:单击开始"按钮后,我如何打开两个(或三个或更多)webkit (QWidget) 窗口,我的意思是,我如何同时启动多个 TestBot所以他们并行完成所有工作?

Now my question: After clicking on the button 'Go', how do I open two (or three or more) webkit (QWidget) windows, I mean, how do I launch several TestBots simultaneously so they do all the work parallel?

我明白,我需要查看多线程,我想我需要将 QThread 继承到我的 TestBot 类定义中,作为class TestBot : public QThread",但这是正确的解决方案吗,我做对了吗?接下来要做什么?

I understood, that I need to look at multithreads, I came up I need to inherit QThread into my TestBot class definition as 'class TestBot : public QThread', but is this right solution and do I do it right? What's to do next?

我不能把代码写成:

QThread process1;
QThread process2;
process1->start();
//some code here
process1->quit();

process2->start();
//some code here
process2->quit();

让一切并行?

我是 Winapp 世界的新手,我来自 Web 编程.希望得到您的帮助!

I'm a newbie in Winapp world, I came from Web programming. Hope for your help!

推荐答案

为了一次显示多个窗口,只需将它们排成一行显示即可.

In order to show multiple windows at once, just line them up and show them.

void ShowMultiple()
{
    QWidget *win1 = new QWidget();
    QWidget *win2 = new QWidget();
    QWidget *win3 = new QWidget();

    win1->show();
    win2->show();
    win3->show();
}

此代码运行后,应该会显示 3 个新的(空白)窗口.但是,如果您尝试执行一些需要很长时间才能显示窗口的代码,则情况可能会发生变化.在这种情况下,您可能需要查看线程或 Qt::Concurrent 示例,记住您确实真的不能在任何其他线程中弄乱 UI.

After this code runs, there should be 3 new (blank) windows shown. However, if you are trying to execute some code that takes a long time along with showing the windows, things might change. In that case, you might want to look at the threads or Qt::Concurrent examples, bearing in mind that you really, really can't mess with the UI in any other thread.

这篇关于QT:如何一次打开多个窗口(QWidgets)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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