首页 > 解决方案 > 如何在 Qt 的第二个窗口中设置 UI 小部件?

问题描述

我正在尝试通过Qt在登录(LoginWindow)之后出现的第二个窗口中动态设置文件(或字符串)的QList。第二个窗口是 QDialog。如何与 LsWindow(第二个窗口)的 UI 进行交互?我已经尝试过在 LsWindow.h 中使用 setUi() 函数,但它没有运行。

void LoginWindow::on_loginButton_clicked(){
    // testing login

    this->close();  // close login window

    QStringList strList;  //construct string list
    strList.push_back("A");
    strList.push_back("B");

        QListWidget* l;  // creating a widget
    l->addItems(strList);

    LsWindow* ls = new LsWindow(this);
    ls->show();

    //ls.ui.listWidget = l;   (??)

    ls->exec();
}



//LsWindow class implementation
class LsWindow : public QDialog
{
    Q_OBJECT

public:
    LsWindow(QWidget *parent = Q_NULLPTR);
    ~LsWindow();


private:
    Ui::LsWindow ui;
};

标签: c++qt

解决方案


推荐阅读