我的第一次尝试,所以我可以在Mainwindow.cpp中得到结果,但可能是//不正确
void Dialog::on_buttonBox_accepted()
{
Cities.clear();
for(int row = 0; row<ui->tableWidget->rowCount(); row++)
{
cities s(get_city(row),get_time(row,3),get_time(row,4));
Cities.push_back(s);
}
}
// my attempt to make another button but I could not get a result in
//Mainwindow.cpp but could check correctly
void Dialog::on_pushButton_clicked()
{
if(cities_is_filled())
{
Cities.clear();
for(int row = 0; row<ui->tableWidget->rowCount(); row++)
{
cities s(get_city(row),get_time(row,3),get_time(row,4));
Cities.push_back(s);
}
}
}
//GET RESULT
void MainWindow::on_actionAdd_train_triggered()
{
Dialog e;
if(e.exec())
{
for(auto City: e.Cities)
{
ui->textBrowser->append(City.city_+ " " + City.depart_+ " "
+City.leave_);
}
}
}
如果按OK键时表格单元格为空,则对话框会关闭 - 但我希望不关闭。我该如何实现呢?
答案 0 :(得分:0)
在buttonBox
上按鼠标右键,然后选择Go To Slot...
,然后选择accepted()
广告位。
现在将您的条件添加到接受的函数中:
void MainWindow::on_buttonBox_accepted()
{
if(ui->tableWidget->item(1,2)->text() != "") // for example
{
}
else
{
qApp->exit();
}
}