简体   繁体   English

使用两个用户界面 - Qt 5.5

[英]Working with two user interfaces - Qt 5.5

I have a simple MainWindow which has a button and an LineEdit .我有一个简单的MainWindow ,它有一个按钮和一个LineEdit When I type something and click a button, a new Dialog appears with a label that is supposed to display the string I typed.当我键入内容并单击按钮时,会出现一个带有标签的新Dialog ,该标签应该显示我键入的字符串。 So basically, I have trouble sending information to another UI.所以基本上,我无法将信息发送到另一个 UI。 I tried working with the new class with a string variable, but it didn't work.我尝试使用带有字符串变量的新类,但没有奏效。

I will try to give an example of what I want to do.我将尝试举例说明我想做的事情。

//ui2 Dialog
    ui2->label->setText(ui->LineEdit->text());

Ui is a an private variable, so it's not accessible from another class. Ui 是一个私有变量,因此不能从另一个类访问。

//mainwindow.cpp
MainWindow::MainWindow(QWidget*){
   this->_dialog = new Dialog(this);
   //...
}
MainWindow::on_pushButton_clicked(){
   _dialog->_labe->setText(ui->lineEdit->text());
}

//dialog.h
class Dialog{
public:
  QLabel* _label;
  Dialog(QWidget* ){
    _label = ui->label;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM