void CTool::load_data_from_db() { myData *db = myData::getMyData(); string sql = "SELECT * FROM car"; int row = 0, col = 0; char ** qres; db->getData_exec(sql.c_str(), row, col, qres); vector<myData> data_list; for (int i = 0; i < row; i++) { myData data; for (int j = 0; j < col; j++) { if (qres[i * col + j] != NULL) { if (j == 0) data.id = atoi(qres[i * col + j]); else if (j == 1) data.name = qres[i * col + j]; else if (j == 2) data.color = qres[i * col + j]; else if (j == 3) data.price = atof(qres[i * col + j]); } } data_list.push_back(data); } for (int i = 0; i < data_list.size(); i++) { CEditBox* edit_box = new CEditBox(x + 10, y + 10 + i * 30, w - 20, 20); edit_box->setText(data_list[i].name + " " + to_string(data_list[i].age)); ctrlArry.push_back(edit_box); } }修改这段代码
时间: 2023-06-14 09:04:05 浏览: 78
void CTool::load_data_from_db() {
myData *db = myData::getMyData();
string sql = "SELECT * FROM car";
int row = 0, col = 0;
char ** qres;
db->getData_exec(sql.c_str(), row, col, qres);
vector<myData> data_list;
for (int i = 0; i < row; i++) {
myData data;
for (int j = 0; j < col; j++) {
if (qres[i * col + j] != NULL) {
if (j == 0)
data.id = atoi(qres[i * col + j]);
else if (j == 1)
data.name = qres[i * col + j];
else if (j == 2)
data.color = qres[i * col + j];
else if (j == 3)
data.price = atof(qres[i * col + j]);
}
}
data_list.push_back(data);
}
for (int i = 0; i < data_list.size(); i++) {
string text = data_list[i].name + " " + to_string(data_list[i].price); // 修改文本框的显示内容
CEditBox* edit_box = new CEditBox(x + 10, y + 10 + i * 30, w - 20, 20);
edit_box->setText(text);
ctrlArry.push_back(edit_box);
}
}
阅读全文