Beginner QT Programming question

I'm pretty new to QT ('bout two days of experience) and I'm just writing a simple program to kind of just figure out the way it works. The program has two radio buttons, a horizontal slider, and two progress bars. What I want the program to do, is when the first radio button is clicked and the horizontal slider is moved, the first progress bar reflects that movement.

Right now, the problem I'm having is that when the program starts and one of the buttons is already selected, the program works correctly until I click the other radio button. If I start the program before any buttons are selected the program doesn't work at all.

This is the mainwindow.cpp file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // check to see what button is pressed


    if(ui->radioButton_2->isChecked())
    {
        connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), ui->progressBar_2, SLOT(setValue(int)));
        disconnect(ui->horizontalSlider, SIGNAL(valueChanged(int)), ui->progressBar, SLOT(setValue(int)));
    }

    else if(ui->radioButton->isChecked())
    {
        connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), ui->progressBar, SLOT(setValue(int)));
        disconnect(ui->horizontalSlider, SIGNAL(valueChanged(int)), ui->progressBar_2, SLOT(setValue(int)));
    }



}

MainWindow::~MainWindow()
{
    delete ui;
}


Any help is appreciated. I tried using while loops, but that didn't work at all. The program didn't even launch.
The MainWindow constructor is only called once, on program start-up.

You can connect one of the QRadioButton signals ( e.g. QRadioButton::toggled(bool) ) to a slot and do your connect/disconnect there.

Here is a link to a good Qt forum: http://www.qtcentre.org/forums/4-Newbie

Also, just a heads up: the "t" in Qt is lower case.
Ok awesome thanks! I'll keep that in mind about the Qt.
Topic archived. No new replies allowed.