Showing different Class from main.cpp

前端 未结 1 717
一生所求
一生所求 2021-01-24 06:27

I am new to qt. i have an application which have several forms.

i am trying to select the specific form from main.cpp, but it just flickered the form. But i am getting th

相关标签:
1条回答
  • 2021-01-24 06:41

    The problem is that w in both cases have a limited scope inside the "if" so they are destroyed instantly. One solution is to use pointers managing dynamic memory, for example using QScopedPointer:

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        QScopedPointer<QWidget> w;
    
        int theme  = 2;
    
        if(theme == 1)
        {
            w.reset(new Design1);
        }
        else{
          w.reset(new Dialog);
        }
    
        if(w){
            w->showMaximized();
            w->show();
        }
    
        return a.exec();
    }
    
    0 讨论(0)
提交回复
热议问题