gpt4 book ai didi

qt - 如何串联QStrings?

转载 作者:行者123 更新时间:2023-12-03 21:08:19 25 4
gpt4 key购买 nike

我在Qt中打印有问题。

我在QString变量中有HTML代码。在这段代码中,我想从数据库中插入数据。

我收到一个错误:

E:\apprendreQt\gestionstock6\vente.cpp:117: error: invalid operands of types 
'const char*' and 'const char [27]' to binary 'operator+'


我怎样才能解决这个问题?

这是我的代码:

int num_bl = ui->numeroBLlineEdit->text().toInt() ;
QString html;
QString requette = "select num_facture,date,nom,prenom,code_fiscale,designation,qte_out, prix,(qte_out * prix ) as Montant, sum(qte_out * prix) as Total from ventes join produits_en_ventes join clients join produits on ventes.vente_id = produits_en_ventes.vente_id and ventes.client_id = clients.client_id and produits_en_ventes.produit_id = produits.produit_id where ventes.client_id = :client_id ";

if(!m_db->isOpen())
QMessageBox::critical(this,tr("Inventoria Solution"),m_db->lastError().text()) ;
else{
m_query->clear();
m_query->prepare(requette);
m_query->bindValue(":client_id ", num_bl);

if(!m_query->exec())
QMessageBox::critical(this,tr("Inventoria Solution"),m_query->lastError().text()) ;
else{
html += " <table>"
"<thead>"
"<tr>"
"<th>N°</th>"
"<th>Désignation</th>"
"<th>Qte</th>"
"<th>Prix Unitaire</th>"
"<th>Montant</th>"
" </tr>"
"</thead>";
while(m_query->next())
{
int num_article = 1;

html += "<tr> <td>" + num_article + "</td> <td>"+m_query->value(5).toString()+"</td> <td>"+m_query->value(6).toInt() + "</td> <td>"+m_query->value(7).toInt() + "</td> <td>" + m_query->value(8).toInt() + "</td></tr>";
num_article++;

}
html += "<tfoot>"
"<tr>"
"<td>Total:"+ m_query->value(9).toInt()+"</td>"
"</tr>"
"</tfoot>"
"</table>";
}
print_Html(html);


}

最佳答案

如果使用operator+,则需要提供QString作为参数,但是要使用整数值:html += "<tr> <td>" + num_article,其中num_article被声明为整数。您可以将其替换为例如:QString::number(num_article)。在这一行中相同:

"<td>Total:"+ m_query->value(9).toInt()+"</td>"


应该替换为

"<td>Total:"+ m_query->value(9).toString()+"</td>"

关于qt - 如何串联QStrings?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18826007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com