QT通过全局变量窗口之间传输参数

2020-12-22 15:01:33  阅读 3899 次 评论 0 条

以下代码目的就是实现 双击弹出窗口 为编辑准备的 用了这种简单的方法来实现。

发送端:

void FormAssets_brow::on_tableWidget1_cellDoubleClicked(int row, int column)
{
    //获取ID号 便于数据库中读取资料数据
    QString idd=ui->tableWidget1->item(row,7)->text(); //第7列为自动编号
    QString test=ui->tableWidget1->item(row,column)->text(); //这行无意义,只为了清除一个警告提示。
    mySQL::SendString="idd="+idd;
    FormAssets_input  * FormAssets_input = new class FormAssets_input;
    FormAssets_input->show();

}

接受端:

            //判断全局变量的参数 如果不为空的话,进行查询语句
            
            if(mySQL::SendString!=""){
                QSqlQuery query(mySQL::cn);
                QString SQL="SELECT ";
                SQL.append(" * ");
                SQL.append(" from asset_details ");
                SQL.append(" where ");
                SQL.append(" type_id='");
                SQL.append(mySQL::TypeId);
                SQL.append("' ");
                SQL.append(" and ");
                SQL.append(mySQL::SendString);                
                query.exec(SQL);
                while(query.next()){
                    ui->txtAssetsIdd->setText(query.value("idd").toString().trimmed());
                    ui->txtAssetsID->setText(query.value("asset_id").toString().trimmed());
                    ui->txtAssetsName->setText(query.value("asset_name").toString().trimmed());
                    ui->txtAssetsQTY->setText(query.value("asset_qty").toString().trimmed());
                    ui->txtAssetsPrice->setText(query.value("asset_price").toString().trimmed());
                    ui->txtAssetsAmount->setText(query.value("asset_amount").toString().trimmed());
                    ui->txtAssetsNote->setText(query.value("asset_notes").toString().trimmed());
                    ui->txtAssetsMonth->setText(query.value("asset_month").toString().trimmed());
                    ui->txtAssetsSize->setText(query.value("asset_size").toString().trimmed());
                    ui->cmbAssetState->setCurrentText(query.value("asset_state").toString().trimmed());
                    ui->cmbAssetsType->setCurrentText(query.value("asset_type").toString().trimmed());
                    ui->cmbAssetsUnit->setCurrentText(query.value("asset_unit").toString().trimmed());
                    ui->cmbAssetsUser->setCurrentText(query.value("asset_user").toString().trimmed());
                    ui->cmbAssetsBuyer->setCurrentText(query.value("asset_buyer").toString().trimmed());
                    ui->cmbAssetsPlace->setCurrentText(query.value("asset_place").toString().trimmed());
                    ui->cmbAssetsMethod->setCurrentText(query.value("asset_method").toString().trimmed());
                    ui->DtAssetsDate->setDate(query.value("asset_date").toDate());
                }
                query.clear();
                mySQL::SendString=""; //处理完成后全局变量应当及时赋值为空
            }
}


本文地址:http://jinesc.cn/?id=243
免责声明:本文为原创文章,版权归 jinesc 所有,欢迎分享本文,转载请保留出处!

发表评论


表情

还没有留言,还不快点抢沙发?