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

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());
}

最佳答案

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

todoList->addItem(taskQry.value(1).toString());

关于c++ - 预期在“*” token 之前的主要表达式?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10159131/

10-13 09:29