2012-04-15 52 views
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()); 
} 
+0

你的意思'todoList->的addItem(新QListWidgetItem(taskStr->追加( taskQry.value(1)的ToString())));'? – Torious 2012-04-15 02:50:12

+0

這似乎確定了錯誤,但現在它說「缺少終止>字符」。那是什麼意思? - 我明白了,我錯過了一個包含的支架 - 我是個白癡。 – Rob 2012-04-15 02:51:57

+0

在堆上創建QStrings是無意義的。它們隱含地共享,因此便宜地複製。 – 2012-04-15 08:38:06

回答

1

我不確定你在做什麼。但是,這將使它編譯:

todoList->addItem(taskQry.value(1).toString()); 
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); 
     } 
相關問題