与将文本存储到Qtablewidget中相反

时间:2019-06-18 16:13:29

标签: c++ qt

我可以使用以下代码将字符串存储到Qtablewidget中:

string ligne;
int row(0);
int col(0);
while(getline(fichier,ligne))
{
    ui->TachesNonRecurrentes->setItem(row, col, new QTableWidgetItem(ligne.c_str()));
    ++col;
    if(col==4)
        {
        col=0;
        ++row;
        ui->TachesNonRecurrentes->setRowCount(row+1);
        }
}

但是我该怎么做相反呢?即请求Qtablewidget取回变量中的文本。我相信这段代码适用于特定元素:

string item1;
item1=ui->TachesNonRecurrentes->item(1,0)->text();

但是我得到了错误:

  

没有可行的重载'='

我可以使用qDebug()

qDebug() << ui->TachesNonRecurrentes->item(1,0)->text();

但是我不知道如何将结果放入变量item1

你能帮忙吗?

0 个答案:

没有答案