PDA

View Full Version : problem in qt hello world programme



u04f061
7th March 2007, 11:59
i am new user of qt and i am running ubuntu dapper linux.i got this hello world programe from trolltech official site. i could not run this programe. i got an error.here it is

#include <qapplication.h>
#include <qpushbutton.h>g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o main.o main.cpp
main.cpp: In function ‘int main(int, char**)’:
main.cpp:12: error: ‘class QApplication’ has no member named ‘setMainWidget’
make: *** [main.o] Error 1




int main( int argc, char **argv )
{
QApplication a( argc, argv );

QPushButton hello( "Hello world!", 0 );
hello.resize( 100, 30 );

a.setMainWidget( &hello );
hello.show();
return a.exec();
}

then i made .pro file with name main.pro using qmake -project
here is this file

################################################## ####################
# Automatically generated by qmake (2.00a) Wed Mar 7 15:54:23 2007
################################################## ####################

TEMPLATE = app
TARGET +=
DEPENDPATH += .
INCLUDEPATH += .

# Input
SOURCES += main.cpp


then i made make file using qmake
then i ran the command make. after short time it gave the following error

g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o main.o main.cpp
main.cpp: In function ‘int main(int, char**)’:
main.cpp:12: error: ‘class QApplication’ has no member named ‘setMainWidget’
make: *** [main.o] Error 1

jpn
7th March 2007, 12:03
Looks like you have installed Qt4 but are trying to compile an old Hello World for Qt3 (http://doc.trolltech.com/3.3/tutorial1-01.html). Try Hello World for Qt4 (http://doc.trolltech.com/4.2/tutorial-t1.html).

patrik08
7th March 2007, 12:09
i am new user of qt and i am running ubuntu dapper linux.i got this hello world programe from trolltech official site. i could not run this programe. i got an error.here it is
int main( int argc, char **argv )
{
QApplication a( argc, argv );

QPushButton hello( "Hello world!", 0 );
hello.resize( 100, 30 );


hello.show();
return a.exec();
}

ror 1


QApplication is not a widget remove line a.setMainWidget( &hello ); or insert a widged..




#include <QApplication>
#include <QLabel>

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

QLabel label("Hallo Welt!");
label.show();

return a.exec();
}



or ....




#include <QApplication>
#include <QPushButton>

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

QPushButton button("Beenden");
button.show();

QObject::connect(&button, SIGNAL(clicked()),
&a, SLOT(quit()));

return a.exec();
}




or... ++ QWidget window;




#include <QApplication>
#include <QVBoxLayout>
#include <QLabel>
#include <QSpinBox>
#include <QSlider>

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

QWidget window;

QVBoxLayout* mainLayout = new QVBoxLayout(&window);
QLabel* label = new QLabel("0");
QSpinBox* spinBox = new QSpinBox;
QSlider* slider = new QSlider(Qt::Horizontal);

mainLayout->addWidget(label);
mainLayout->addWidget(spinBox);
mainLayout->addWidget(slider);

QObject::connect(spinBox, SIGNAL(valueChanged(int)),
label, SLOT(setNum(int)));
QObject::connect(spinBox, SIGNAL(valueChanged(int)),
slider, SLOT(setValue(int)));
QObject::connect(slider, SIGNAL(valueChanged(int)),
label, SLOT(setNum(int)));
QObject::connect(slider, SIGNAL(valueChanged(int)),
spinBox, SLOT(setValue(int)));

window.show();

return a.exec();
}

u04f061
7th March 2007, 12:29
still having a problem. following error occurs

g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o qt4h.o qt4h.cpp
g++ -o qt4h qt4h.o -L/usr/lib -lQtGui_debug -lQtCore_debug -lpthread
/usr/bin/ld: cannot find -lQtGui_debug
collect2: ld returned 1 exit status
make: *** [qt4h] Error 1

i think i am missing some package.i am installing libqt4-debug from repository. its size is 51MB.am i right or there is some other faylt?

patrik08
7th March 2007, 12:42
still having a problem. following error occurs
i think i am missing some package.i am installing libqt4-debug from repository. its size is 51MB.am i right or there is some other faylt?

How you installed qt only static && release .... or you get the new Ubuntu Feisy ready to use package qt4.2 ?

u04f061
9th March 2007, 12:11
How you installed qt only static && release .... or you get the new Ubuntu Feisy ready to use package qt4.2 ?


i installed qt from repository. its download size was 4Mb and install size was 51Mb. the package names i don't remember

jpn
9th March 2007, 12:39
So, the problem was solved? (Yes, you were missing the debug libs)