本人初学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);//显示对应的帮助
请各位高手指点一下,在下不胜感激,与君共勉!
数据库表中含有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);//显示对应的帮助
请各位高手指点一下,在下不胜感激,与君共勉!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货