C++ Gui

Since i m new to c++ gui so tell me how to use QT ....
I mean how to make simple hello world program in QT .....
I dont know How to open the correct wizard to start
i have qt 3.0.1
plz guide me ...........

Try this, google is your friend.

http://bit.ly/1jDss2i
why are you using such an old version of QT?
now i have installd 5.1.1 and it is now saying that it needs a compiler setup??? i don't know how to solve this???

What better place to look than the QT website itself

https://qt-project.org/doc/

Here's one:
It's a number pad. Press buttons to add digits to your number, then press enter and it'll print the number to stdout.
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <iostream>
#include <QApplication>
#include <QDialog>
#include <QString>
#include <QLineEdit>
#include <QPushButton>

class NumPad : public QDialog
{
    Q_OBJECT
public:
    explicit NumPad(QWidget *parent = 0);
    void retranslateUi(QDialog *n);
    ~NumPad() {}
    int getInt()            { return m_string.toUInt();   }
    double getDouble()      { return m_string.toDouble(); }
private slots:
    void on_m_0_clicked()   { addChar('0');   }
    void on_m_1_clicked()   { addChar('1');   }
    void on_m_2_clicked()   { addChar('2');   }
    void on_m_3_clicked()   { addChar('3');   }
    void on_m_4_clicked()   { addChar('4');   }
    void on_m_5_clicked()   { addChar('5');   }
    void on_m_6_clicked()   { addChar('6');   }
    void on_m_7_clicked()   { addChar('7');   }
    void on_m_8_clicked()   { addChar('8');   }
    void on_m_9_clicked()   { addChar('9');   }
    void on_m_dot_clicked() { addChar('.');   }
    void on_m_ok_clicked()  { this->accept(); }
    void on_m_esc_clicked() { this->reject(); }

private:
    void addChar(char c)
    {
        m_string.append( c );
        m_display->setText(m_string);
    }

    QString m_string;
    QLineEdit   *m_display;
    QPushButton *m_0, *m_1, *m_2, *m_3, *m_4;
    QPushButton *m_5, *m_6, *m_7, *m_8, *m_9;
    QPushButton *m_dot, *m_ok, *m_esc;
};

NumPad::NumPad(QWidget *parent) : QDialog(parent)
{
    if (this->objectName().isEmpty())
        this->setObjectName(QString::fromUtf8("NumPad"));
    this->resize(270, 300);

    m_0       = new QPushButton(this);
    m_1       = new QPushButton(this);
    m_2       = new QPushButton(this);
    m_3       = new QPushButton(this);
    m_4       = new QPushButton(this);
    m_5       = new QPushButton(this);
    m_6       = new QPushButton(this);
    m_7       = new QPushButton(this);
    m_8       = new QPushButton(this);
    m_9       = new QPushButton(this);
    m_dot     = new QPushButton(this);
    m_ok      = new QPushButton(this);
    m_esc     = new QPushButton(this);
    m_display = new QLineEdit  (this);

    m_0->setObjectName      (QString::fromUtf8("m_0"));
    m_1->setObjectName      (QString::fromUtf8("m_1"));
    m_2->setObjectName      (QString::fromUtf8("m_2"));
    m_3->setObjectName      (QString::fromUtf8("m_3"));
    m_4->setObjectName      (QString::fromUtf8("m_4"));
    m_5->setObjectName      (QString::fromUtf8("m_5"));
    m_6->setObjectName      (QString::fromUtf8("m_6"));
    m_7->setObjectName      (QString::fromUtf8("m_7"));
    m_8->setObjectName      (QString::fromUtf8("m_8"));
    m_9->setObjectName      (QString::fromUtf8("m_9"));
    m_ok->setObjectName     (QString::fromUtf8("m_ok"));
    m_dot->setObjectName    (QString::fromUtf8("m_dot"));
    m_esc->setObjectName    (QString::fromUtf8("m_esc"));
    m_display->setObjectName(QString::fromUtf8("m_display"));

    m_0->setGeometry(      QRect(20 , 240, 111, 51 ));
    m_1->setGeometry(      QRect(20 , 180, 51 , 51 ));
    m_2->setGeometry(      QRect(80 , 180, 51 , 51 ));
    m_3->setGeometry(      QRect(140, 180, 51 , 51 ));
    m_4->setGeometry(      QRect(20 , 120, 51 , 51 ));
    m_5->setGeometry(      QRect(80 , 120, 51 , 51 ));
    m_6->setGeometry(      QRect(140, 120, 51 , 51 ));
    m_7->setGeometry(      QRect(20 , 60 , 51 , 51 ));
    m_8->setGeometry(      QRect(80 , 60 , 51 , 51 ));
    m_9->setGeometry(      QRect(140, 60 , 51 , 51 ));
    m_ok->setGeometry(     QRect(200, 180, 51 , 111));
    m_dot->setGeometry(    QRect(140, 240, 51 , 51 ));
    m_esc->setGeometry(    QRect(200, 60 , 51 , 111));
    m_display->setGeometry(QRect(20 , 10 , 231, 41 ));

    retranslateUi(this);

    QMetaObject::connectSlotsByName(this);
}

void NumPad::retranslateUi(QDialog *n)
{
    n->setWindowTitle(QApplication::translate("NumPad", "Dialog", 0, QApplication::UnicodeUTF8));
    m_7->setText(  QApplication::translate("NumPad", "7", 0, QApplication::UnicodeUTF8));
    m_4->setText(  QApplication::translate("NumPad", "4", 0, QApplication::UnicodeUTF8));
    m_1->setText(  QApplication::translate("NumPad", "1", 0, QApplication::UnicodeUTF8));
    m_0->setText(  QApplication::translate("NumPad", "0", 0, QApplication::UnicodeUTF8));
    m_8->setText(  QApplication::translate("NumPad", "8", 0, QApplication::UnicodeUTF8));
    m_9->setText(  QApplication::translate("NumPad", "9", 0, QApplication::UnicodeUTF8));
    m_5->setText(  QApplication::translate("NumPad", "5", 0, QApplication::UnicodeUTF8));
    m_6->setText(  QApplication::translate("NumPad", "6", 0, QApplication::UnicodeUTF8));
    m_2->setText(  QApplication::translate("NumPad", "2", 0, QApplication::UnicodeUTF8));
    m_3->setText(  QApplication::translate("NumPad", "3", 0, QApplication::UnicodeUTF8));
    m_dot->setText(QApplication::translate("NumPad", ".", 0, QApplication::UnicodeUTF8));
    m_ok->setText( QApplication::translate("NumPad", "OK", 0, QApplication::UnicodeUTF8));
    m_esc->setText(QApplication::translate("NumPad", "ESC", 0, QApplication::UnicodeUTF8));
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    NumPad n(0);
    n.exec();

    std::cout << n.getDouble();

    return a.exec();
}



Or if you use Qt Creator to make it with a form, it gets shortened to this:
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <QDialog>
namespace Ui {
class NumPad2;
}

class NumPad2 : public QDialog
{
    Q_OBJECT
    
public:
    explicit NumPad2(QWidget *parent = 0);
    ~NumPad2() { delete ui; }
    
private slots:
    void on_m_0_clicked()   { addChar('0');   }
    void on_m_1_clicked()   { addChar('1');   }
    void on_m_2_clicked()   { addChar('2');   }
    void on_m_3_clicked()   { addChar('3');   }
    void on_m_4_clicked()   { addChar('4');   }
    void on_m_5_clicked()   { addChar('5');   }
    void on_m_6_clicked()   { addChar('6');   }
    void on_m_7_clicked()   { addChar('7');   }
    void on_m_8_clicked()   { addChar('8');   }
    void on_m_9_clicked()   { addChar('9');   }
    void on_m_dot_clicked() { addChar('.');   }
    void on_m_ok_clicked()  { this->accept(); }
    void on_m_esc_clicked() { this->reject(); }

private:
    void addChar(char c);

    QString m_string;

    Ui::NumPad2 *ui;
};
//////////////////////////////
// Numpad2.cpp
#include "Numpad2.h"
#include "ui_numpad2.h" // <-- This is autogenerated

NumPad2::NumPad2(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::NumPad2)
{
    ui->setupUi(this);
}

void NumPad2::addChar(char c)
{
    m_string.append( c );
    ui->m_display->setText(m_string);
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    NumPad2 n(0);
    n.exec();

    std::cout << n.getDouble();

    return a.exec();
}


Actually, if you're using Qt Creator, there's a great "Examples" and "Tutorials" section available if you click on the "Welcome" tab.
Last edited on
now i have installd 5.1.1 and it is now saying that it needs a compiler setup??? i don't know how to solve this???


The latest version is 5.3.1 so start off by getting the that version. On Windows, Qt uses the Visual Studio compiler and you have to link to it and/or install Widows7 SDK, or something like that I forget exactly. To make it simple just go to the download page:
https://qt-project.org/downloads
click "Show Downloads" and select this one:
Qt 5.3.1 for Windows 32-bit (MinGW 4.8.2, OpenGL, 735 MB)
Then you can start working on some of the examples.
Thanks to all of you
Will you tell me what version of visual studio is exactly required for this ??
Why would use visual studio for this? QT comes with an IDE
Just get the installer I mentioned and save yourself a lot of frustration.
Generally, you'd use Qt creator instead of visual studio. That comes with a nice GUI editor meant for Qt, has the libraries already installed, and has syntax highlighting for macros like private slots.

If you want to use visual studio, you're definitely doing things the hard way, but there are valid reasons for doing so (perhaps this is what your workplace uses, or you're integrating with a larger project and want this to be part of the same .sln).

To use this for visual studio, you need to install the Qt library. Go the link posted above and click: "Not the version you wanted? Show downloads". Then you can find a package for VS, choose whether you want OpenGL or 64 bit versions, then install that. To use it in a project, you'll probably need to link to the appropriate library, but there should be some tutorial on that website for that.
Thanks to all of you
i have got it working .........yeahhhhhh
Topic archived. No new replies allowed.