QComboBox 点击事件
//点击cmbType的信号槽 connect(ui->cmbType,&QComboBox::currentTextChanged,[=](){ QString typeID=ui->cmbType->currentText(); QString SQL=""; QSqlQuery query(mySQL::cn); SQL=""; SQL.append("SELECT "); //SQL.append(" * "); SQL.append("asset_id,asset_type,asset_name,asset_unit,"); SQL.append("asset_qty,asset_price,asset_amount,asset_date,asset_buyer,"); SQL.append("asset_user,asset_place,asset_State,asset_method,asset_month,asset_notes "); SQL.append(" FROM asset_details"); SQL.append(" where "); SQL.append(" type_id='"); SQL.append(mySQL::TypeId); SQL.append("' "); SQL.append(" and asset_type='"); SQL.append(typeID); SQL.append("' "); SQL.append(" order by asset_type,asset_id"); query.exec(SQL); QStringList list1; list1.clear(); list1<<"资产类别"<<"资产名称"<<"资产ID"<<"数量"<<"单价"<<"使用人"; ui->tableWidget->clear(); ui->tableWidget->setColumnCount(list1.size()); ui->tableWidget->setHorizontalHeaderLabels(list1); int row=0; ui->tableWidget->setRowCount(20); //暂时设置成20行 while(query.next()) { ui->tableWidget->setItem(row,0,new QTableWidgetItem(query.value("asset_type").toString())); ui->tableWidget->setItem(row,1,new QTableWidgetItem(query.value("asset_name").toString() )); ui->tableWidget->setItem(row,2,new QTableWidgetItem(query.value("asset_id").toString())); ui->tableWidget->setItem(row,3,new QTableWidgetItem(query.value("asset_qty").toString()+query.value("asset_unit").toString() )); ui->tableWidget->setItem(row,4,new QTableWidgetItem(query.value("asset_price").toString())); ui->tableWidget->setItem(row,5,new QTableWidgetItem(query.value("asset_user").toString())); row++; ui->tableWidget->setRowCount(row+1); } });
发表评论