从QT中的对话框访问主窗口

access main window from dialog in qt

本文关键字:访问 窗口 对话框 QT      更新时间:2023-10-16

在主窗口中,他们的laneDit_1和对话框中的landit_2。单击按钮后,对话框窗口将打开。现在,我需要LENEDIT_2在主窗口中获取landedit_1的值。

(主窗口类是MainWindow,对话框窗口类是dialog

我试图这样做,但是它给出了一个错误 error: ISO C++ forbids declaration of 'MainWindow' with no type

对话框

MainWindow *main; //declair a pointer to the main window

dialog.cpp

lineEdit_2->setText(main->lineEdit_1->text());

这里有什么错误。

我会非常感谢任何建议。谢谢。

      void dialog::lineText(QString text){
       lineEdit_text = text;  //let lineEdit_text be a QString member in your 
                              //dialog class. Pass the text before calling
                              //setVisible() in the client code
     }