View Single Post
Posts: 180 | Thanked: 76 times | Joined on May 2010
#111
You can use member variable to access variables in other method.

MainWindow.h
Code:
class MainWindow
{
...
private:
    QStringList fonts;
}
MainWindow.cpp
Code:
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    progress("Setting up the theme, please wait...", "Abort", 0, 0, this),
    colors()
{
    ui->setupUi(this);
    ui->scrollArea->setWidget(ui->widget);
    readdirs();
    QString oldfont1 = ui->font1->text();
    QString oldfont2 = ui->font2->text();
    QString oldfont3 = ui->font3->text();
    QString oldfont4 = ui->font4->text();
    fonts.append(oldfont1);
    fonts.append(oldfont2);
    fonts.append(oldfont3);
    fonts.append(oldfont4);
//    readSettings();
}
Maybe change the method name to be more descriptive
Code:
void MainWindow::on_pushButton_clicked()
{
     fonts.at(0); //do something to oldfont1 string
}
 

The Following User Says Thank You to Diph For This Useful Post: