Gui Qt

My Program does not work
It says the program stopped working ......

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
33
34
 #include "mainwindow.h"
#include <QApplication>
#include <QWidget>
#include <QMainWindow>
#include <QSlider>
#include <QSpinBox>
#include <QGridLayout>
#include <QObject>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QSlider *slider ;
    QSpinBox *spinBox ;
    QGridLayout *layout ;
    QWidget *window;
    window=new QWidget();
    window->setWindowTitle("Love is To Redeem");
    spinBox = new QSpinBox();
    spinBox->setRange(0,100);
    slider = new QSlider(Qt::Horizontal);
    slider->setRange(0,100);
    QObject::connect(spinBox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
    QObject::connect(slider,SIGNAL(valueChanged(int)),spinBox,SLOT(setValue(int)));
    spinBox->setValue(0);
    layout->addWidget(spinBox);
    layout->addWidget(slider);
    window->setLayout(layout);
    window->show();



    return a.exec();
}


And plz tell me what this sentence means exactly
all i know is that it generates and recieves signals but how does this work

connect( button0, SIGNAL(clicked()), mapper, SLOT(map()) );
Last edited on
I'm not that familiar with qt but I believe you need.
layout = new QGridLayout; somewhere.

And plz tell me what this sentence means exactly

it connects button0's signal clicked to mapper's slot map() so when button0 is clicked map() is executed.
Why are you doing all that in main.cpp? In almost every case all I ever have in there is:
1
2
3
4
5
6
7
8
9
10
11
#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}


It is not clear if you are trying to make a main window or just widget, although I will assume widget in which case the first include would be widget.h instead of mainwindow.h. The main.cpp is only meant to initialize the program and everything else should have its own class with a .h and .cpp file. If you use creator all that will be done for you for the most part along with creating a .ui file that contains most of what you have in XML format.

I see now that you have a mainwindow.h, that is where you should be adding code along with mainwindow.cpp.
Last edited on
Thanks bro..........
Topic archived. No new replies allowed.