Im using Qt creator 3.5.1 and creating a simple gui.
Im wondering how to get data from combobox that is in qstringlist here's my code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
list=(QStringList()<<"Japan"<<"Korea"<<"Philippines"<<"Us");
ui->comboBox->addItems(list);
ui->comboBox_2->addItems(list);
str1 = ui->comboBox->currentText();
str2 = ui->comboBox_2->currentText();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
integer_value = ui->lineEdit->text().toInt();
if(str1 == "Us" && str2 == "Philippines")
{
answer = integer_value * 47.73;
result = result.number(answer);
ui->label->setText(result);
}
}
when im using this code it works:
without using QStringList:
ui->comboBox->addItem("Us");
ui->comboBox_2->addItem("Philippines");
You initialize str1 and str2 once (with "Japan"), and they never changed (according to your code). If you want to get current comboBox text when you press button, you need to check it in on_pushButton_clicked()
slot. Something like that:
void MainWindow::on_pushButton_clicked()
{
str1 = ui->comboBox->currentText();
str2 = ui->comboBox_2->currentText();
if(str1 == "Us" && str2 == "Philippines")
{
answer = integer_value * 47.73;
result = result.number(answer);
ui->label->setText(result);
}
}