qt - Get Data from qcombo box in stringlist data -


im using qt creator 3.5.1 , creating simple gui.

im wondering how data combobox in qstringlist here's 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 code works:

without using qstringlist:

ui->combobox->additem("us"); ui->combobox_2->additem("philippines"); 

you initialize str1 , str2 once (with "japan"), , never changed (according code). if want current combobox text when press button, need check in on_pushbutton_clicked() slot. 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);         } } 

Comments