You are not logged in.

#1 2009-03-28 00:45:40

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

[SOLVED] Qt Hello World

I found this website http://doc.trolltech.com/3.0/t1.html which shows how to write a hello world programme using QT. I wanted to try it out myself but ran into these errors (among others),

hi.c:1:26: error: qapplication.h: No such file or directory
hi.c:2:25: error: qpushbutton.h: No such file or directory

I've got qt 4.5 but figure I need the development package. However, I cannot seem to find qt-devel on any of the Arch Linux Repos... Is there some other package that is used for these C headers?

Last edited by tony5429 (2009-03-29 03:10:31)

Offline

#2 2009-03-28 00:47:11

Renan Birck
Member
From: Brazil
Registered: 2007-11-11
Posts: 401
Website

Re: [SOLVED] Qt Hello World

The tutorial is for Qt 3.0, I believe. Try installing 'qt3'.

Offline

#3 2009-03-28 00:49:36

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] Qt Hello World

Oh; good catch. Well rather than learn how to use qt3, I'll look for a qt 4.5 hello world website. Thanks!

Offline

#4 2009-03-28 01:10:57

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] Qt Hello World

The Qt hello world programme on wikipedia works fine:

#include <QtGui/QApplication>
#include <QtGui/QLabel>
 
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QLabel label("Hello, world!");
    label.show();
    return app.exec();
}

Thanks.

Offline

#5 2009-03-28 01:42:47

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] Qt Hello World

Well I'd like to have a button in the programme which allows the user to close the window. However, I find that the button is going on a separate window. Any ideas as to how to make the button on the same window as the "Hello world"?

two_windows.png

#include <QApplication>
#include <QLabel>
#include <QPushButton>

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);

    QLabel label("Hello world!");
    label.show();

    QPushButton *button = new QPushButton("Close the window.");
    QObject::connect(button, SIGNAL(clicked()), &app, SLOT(quit()));
    button->show();

    return app.exec();
}

Offline

#6 2009-03-28 01:44:37

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,392
Website

Re: [SOLVED] Qt Hello World

Moving to "General Programming Forum"...

Offline

#7 2009-03-28 16:44:51

sirius
Member
From: Norway
Registered: 2008-12-25
Posts: 68

Re: [SOLVED] Qt Hello World

You are looking for something like this:

#include <QApplication>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>

int main(int argc, char *argv[]) {
        QApplication app(argc, argv);

        QWidget *window = new QWidget();
        QVBoxLayout *layout = new QVBoxLayout();
        QLabel *label = new QLabel("Hello world!");
        QPushButton *button = new QPushButton("Close the window.");
        QObject::connect(button, SIGNAL(clicked()), &app, SLOT(quit()));

        layout->addWidget(label);
        layout->addWidget(button);
        window->setLayout(layout);

        window->show();
        return app.exec();
}

Offline

#8 2009-03-29 03:10:13

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] Qt Hello World

Perfect; thanks!

Offline

Board footer

Powered by FluxBB