comboBox()把数据传给别的窗口的代码实例
时间: 2023-04-07 08:05:22 浏览: 85
ComboBox Example
以下是一个comboBox()把数据传给别的窗口的代码实例:
在第一个窗口中:
```
QStringList items;
items << "Item 1" << "Item 2" << "Item 3";
QComboBox *comboBox = new QComboBox(this);
comboBox->addItems(items);
QPushButton *button = new QPushButton("传递数据", this);
connect(button, &QPushButton::clicked, [=](){
QString selectedItem = comboBox->currentText();
SecondWindow *secondWindow = new SecondWindow(selectedItem, this);
secondWindow->show();
});
```
在第二个窗口中:
```
SecondWindow::SecondWindow(QString selectedItem, QWidget *parent) : QWidget(parent)
{
QLabel *label = new QLabel("你选择了:" + selectedItem, this);
label->setAlignment(Qt::AlignCenter);
label->setGeometry(0, 0, 200, 100);
}
```
阅读全文