我似乎无法弄清楚这一点!我一直收到一条错误,上面写着“'''令牌之前预期的主要表达式”,没有其他提示。它发生在看起来像
的行上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());
}
答案 0 :(得分:1)
我不确定你要做什么。但这将使其编译:
todoList->addItem(taskQry.value(1).toString());
答案 1 :(得分: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 );
}