PDA

View Full Version : Trouble with QLabel



dany_MB
7th October 2008, 15:01
I'm having troubles with QLabel. This is the code from the book :

// helloWorld/main.cpp
#include <QApplication>
#include <QLabel>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel label("Hello World");
label.show();
return a.exec();
}

main.cpp:2:24: error: QApplication: No such file or directory
main.cpp:3:18: error: QLabel: No such file or directory
main.cpp: In function 'int main(int, char**)':
main.cpp:7: error: 'QApplication' was not declared in this scope
main.cpp:7: error: expected `;' before 'a'
main.cpp:8: error: 'QLabel' was not declared in this scope
main.cpp:8: error: expected `;' before 'label'
main.cpp:9: error: 'label' was not declared in this scope
main.cpp:10: error: 'a' was not declared in this scope
main.cpp: At global scope:
main.cpp:5: warning: unused parameter 'argc'
main.cpp:5: warning: unused parameter 'argv'
make: *** [main.o] Error 1

Than I change in header QApplication to qapplication.h and QLabel to qlabel.h

// helloWorld/main.cpp
#include <qapplication.h>
#include <qlabel.h>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel label("Hello World");
label.show();
return a.exec();
}

main.cpp: In function 'int main(int, char**)':
main.cpp:8: error: no matching function for call to 'QLabel::QLabel(const char [12])'
/usr/lib/qt/include/qlabel.h:163: note: candidates are: QLabel::QLabel(const QLabel&)
/usr/lib/qt/include/qlabel.h:66: note: QLabel::QLabel(QWidget*, const QString&, QWidget*, const char*, uint)
/usr/lib/qt/include/qlabel.h:64: note: QLabel::QLabel(const QString&, QWidget*, const char*, uint)
/usr/lib/qt/include/qlabel.h:62: note: QLabel::QLabel(QWidget*, const char*, uint)
make: *** [main.o] Error 1

Can somebody tell me what is wrong with this?

spirit
7th October 2008, 15:16
looks like that you didn't specify LD_LIBRARY_PATH for Qt.

kavinsiva
14th August 2009, 07:56
use like

QLabel label;
label.setText("hai");
label.show();

spirit
14th August 2009, 08:21
what is difference? the code wich specified author is correct.