我有如下的函数,全局QVector
void MainWindow::on_priority_clicked()
{
int curI = ui->tableWidget->currentRow();
int prio = ui->prioritySpinBox->value();
try{
if(ui->tableWidget->item(curI,1)->text().isNull())
throw curI;
else {
setpriority(PRIO_PROCESS, pid.at(curI),prio);
QLabel *labelPrio = new QLabel(ui->tableWidget);
labelPrio->setText(QString::number(getpriority(PRIO_PROCESS, pid.at(curI))));
ui->tableWidget->setCellWidget(curI, 3, labelPrio);
}
}
catch(int x)
{
QMessageBox::warning(this, "Error", "Process " + QString::number(x+1) + " is not created");
}
}
不确定这是否是您的问题,但如果ui->tableWidget->item(curI,1)
不存在(或为null),则在其上调用->text()
将导致崩溃。您可能需要先检查它是否存在:
void MainWindow::on_priority_clicked()
{
int curI = ui->tableWidget->currentRow();
int prio = ui->prioritySpinBox->value();
try{
if(ui->tableWidget->item(curI,1) != nullptr)
....