隐藏qdialog并显示mainwindow [英] hide qdialog and show mainwindow

查看:271
本文介绍了隐藏qdialog并显示mainwindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Qdialog,其中我有一些输入使用在我的主窗口。所以它必须比mainwindow首先出现。



问题是我的主窗口不显示。这是我的main.cpp

  #include< QtGui / QApplication> 

#includeplanevolume.h
#includedialog.h

int main(int argc,char * argv [])
{
QApplication app(argc,argv);

Dialog * dialog = new Dialog;
dialog-> show();

planevolume mainwindow;

bool dialogcheck = dialog-> isHidden();

if(dialogcheck == 1)
{
mainwindow.show();
}
else
{
}

return app.exec();
}

我有一个按钮,当按下时隐藏qdialog,如果它隐藏主窗口应该出现,对吗?



这里是我使用的SLOT:

  void Dialog :: startplanevolume()
{
if(xMax == 0 || yMax == 0 || zMax == 0 || xMMax == 0 || yMMax == 0 | | zMMax == 0)
{
ui-> label_17-> setText(Error:Can not start,invalid measures);
}
else
{
hide();
}
}

主窗口只能在该按钮点击后才能启动只有这样我才能输入主winodw

解决方案

所以这里的问题是调用dialog-> show()不块执行。打电话的那一刻,它移动到下一个方法。您需要阻止执行,直到用户完成输入。



使您的主题如下所示:

  QApplication app(argc,argv); 

Dialog * dialog = new Dialog;
if(dialog-> exec()){
planevolume mainwindow;
mainwindow.show();
return app.exec();
}
return 0;

在对话框类中,使您的方法看起来像:

  void Dialog :: startplanevolume()
{
if(xMax == 0 || yMax == 0 || zMax == 0 | | xMMax == 0 || yMMax == 0 || zMMax == 0)
{
ui-> label_17-> setText(Error:Can not start,invalid measures);
}
else
{
this-> accept(); //关闭对话框,结果为1
}
}


I have a Qdialog in which i get some inputs to use on my mainwindow. so it must appear first than mainwindow.

the problem is that my mainwindow does not show up. here's my main.cpp

#include <QtGui/QApplication>

#include "planevolume.h"
#include "dialog.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    Dialog *dialog= new Dialog;
    dialog->show();

    planevolume mainwindow;

    bool dialogcheck = dialog->isHidden();

    if (dialogcheck==1)
    {
        mainwindow.show();
    }
    else
    {
    }

    return app.exec();
}

I have a pushbutton that when pressed hides the qdialog and if it is hidden than the mainwindow should show up, right?

here's the SLOT i used:

void Dialog::startplanevolume()
{
    if (xMax==0 || yMax==0 || zMax==0 || xMMax==0 || yMMax==0 || zMMax==0)
    {
        ui->label_17->setText("Error: Can't start, invalid measures");
    }
    else
    {
        hide();
    }
}

the mainwindow can only start after that button is clicked as only then I have the inputs to the main winodw

解决方案

So the problem here is that calling dialog->show() does not block execution. The minute that call is made, it moves on to the next method. You need to block execution until the user finishes putting input in.

Make your main like this:

QApplication app(argc, argv);

Dialog *dialog= new Dialog;
if ( dialog->exec() ) {
    planevolume mainwindow;
    mainwindow.show();
    return app.exec();
}
return 0;

And in your dialog class, make your method look like:

void Dialog::startplanevolume() 
{
    if (xMax==0 || yMax==0 || zMax==0 || xMMax==0 || yMMax==0 || zMMax==0) 
    {
        ui->label_17->setText("Error: Can't start, invalid measures");
    }
    else 
    {
        this->accept();  // close the dialog with a result of 1
    }
}

这篇关于隐藏qdialog并显示mainwindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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