0

我似乎无法弄清楚这一点!我不断收到一条错误消息,上面写着“'*' 标记之前的预期主表达式”,没有其他提示。它发生在看起来像的线上

todoList->addItem(QListWidgetItem *taskStr->append(taskQry.value(1).toString()));

这是什么意思,从我通过搜索发现它似乎是一个语法错误,但有人可以向我解释为什么它是一个语法错误吗?有没有更好的方法将字符串附加到列表中?

todoList = new QListWidget(todoGroupBox);

QSqlDatabase localdb = QSqlDatabase::database("TestERP");
if (localdb.open())
{
    QSqlQuery taskQry;

    if (taskQry.exec("SELECT * FROM erp_data.todo_lists;"))
    {
        if (taskQry.value(1).toString() == "")
        {
            QMessageBox::information(this,"No Connection","Nothing in the Manufacturer Database\n"
                                     "\nError: " + db.lastError().text());
        }
        else
        {
            while (taskQry.next())
            {
                QString *taskStr = new QString;
                todoList->addItem(QListWidgetItem *taskStr->append(taskQry.value(1).toString()));
            }
        }
    }
    else
    {
        QMessageBox::information(new QWidget,"Not Connected","Connection to the Database could not be Established\n"
                                 "\nError: " + db.lastError().text());
    }
}
else
{
    QMessageBox::information(new QWidget,"Not Connected","Connection to the Database could not be Established\n"
                             "\nError: " + db.lastError().text());
}
4

2 回答 2

1

我不确定您要做什么。但这将使它编译:

todoList->addItem(taskQry.value(1).toString());
于 2012-04-15T02:53:02.687 回答
0

可能你需要改变

while (taskQry.next())
        {
            QString *taskStr = new QString;
            todoList->addItem(QListWidgetItem *taskStr->append(taskQry.value(1).toString()));
        }

while (taskQry.next())
        {   
            // The QListWidgetItem is added automatically to todoList
            new QListWidgetItem(taskQry.value(1).toString(), todoList );
        }
于 2012-04-15T18:39:24.470 回答