本人初学Qt,做了个简单的资源管理器,其中用QtreewIdget显示条目,显示为中文,我想单击时,可以从数据库中查看单击item对应的帮助。结果显示是空的。数据用的SQL。
数据库表中含有ID(int),name(string),help(string)
QString currentArithmeticName = currentItem->data(0,0).toString();//获取当前ITEM对应字符串
int col = arithmeticTreeWidget->currentColumn();
QTextCodec *code = QTextCodec::codecForName("gb18030");//字符转换
std::string stringArithmeticName = code->fromUnicode(currentArithmeticName).data();
QSqlQuery  query; 
query.exec("select help from Arithmetic where name like stringArithmeticName");//不能显示
//query.exec("select help from Arithmetic where id = 2");//可以显示
while(query.next())

note = query.value(0).toString();
}
QMessageBox::information(this,tr("help"),note,QMessageBox::Yes);//显示对应的帮助
请各位高手指点一下,在下不胜感激,与君共勉!

解决方案 »

  1.   

    query.exec("select help from Arithmetic where name like stringArithmeticName");改为query.exec("select help from Arithmetic where name like '%'+'+stringArithmeticName+'+'%'");
      

  2.   

    query.exec("select help from Arithmetic where name like ''+stringArithmeticName+'');
      

  3.   

    还是不行,始终无法显示!在MESSAGEBOX里还是空白显示!请各位继续帮助!
      

  4.   

    更正一下,数据库用的SQLITE,最初我以为他们一样,结果发现迥然,希望大家给我点建议,怎么改正
      

  5.   

    The best way is to use internal proc "sql_execute"