Results 1 to 7 of 7

Thread: problem in qt hello world programme

  1. #1
    Join Date
    Mar 2007
    Posts
    3
    Qt products
    Qt4

    Default problem in qt hello world programme

    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



    Qt Code:
    1. int main( int argc, char **argv )
    2. {
    3. QApplication a( argc, argv );
    4.  
    5. QPushButton hello( "Hello world!", 0 );
    6. hello.resize( 100, 30 );
    7.  
    8. a.setMainWidget( &hello );
    9. hello.show();
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by wysota; 7th March 2007 at 11:29. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: problem in qt hello world programme

    Looks like you have installed Qt4 but are trying to compile an old Hello World for Qt3. Try Hello World for Qt4.
    J-P Nurmi

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in qt hello world programme

    Quote Originally Posted by u04f061 View Post
    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..

    Qt Code:
    1. #include <QApplication>
    2. #include <QLabel>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7.  
    8. QLabel label("Hallo Welt!");
    9. label.show();
    10.  
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    or ....

    Qt Code:
    1. #include <QApplication>
    2. #include <QPushButton>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7.  
    8. QPushButton button("Beenden");
    9. button.show();
    10.  
    11. QObject::connect(&button, SIGNAL(clicked()),
    12. &a, SLOT(quit()));
    13.  
    14. return a.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 


    or... ++ QWidget window;


    Qt Code:
    1. #include <QApplication>
    2. #include <QVBoxLayout>
    3. #include <QLabel>
    4. #include <QSpinBox>
    5. #include <QSlider>
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication a(argc, argv);
    10.  
    11. QWidget window;
    12.  
    13. QVBoxLayout* mainLayout = new QVBoxLayout(&window);
    14. QLabel* label = new QLabel("0");
    15. QSpinBox* spinBox = new QSpinBox;
    16. QSlider* slider = new QSlider(Qt::Horizontal);
    17.  
    18. mainLayout->addWidget(label);
    19. mainLayout->addWidget(spinBox);
    20. mainLayout->addWidget(slider);
    21.  
    22. QObject::connect(spinBox, SIGNAL(valueChanged(int)),
    23. label, SLOT(setNum(int)));
    24. QObject::connect(spinBox, SIGNAL(valueChanged(int)),
    25. slider, SLOT(setValue(int)));
    26. QObject::connect(slider, SIGNAL(valueChanged(int)),
    27. label, SLOT(setNum(int)));
    28. QObject::connect(slider, SIGNAL(valueChanged(int)),
    29. spinBox, SLOT(setValue(int)));
    30.  
    31. window.show();
    32.  
    33. return a.exec();
    34. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Mar 2007
    Posts
    3
    Qt products
    Qt4

    Default Re: problem in qt hello world programme

    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?

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in qt hello world programme

    Quote Originally Posted by u04f061 View Post
    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 ?

  6. #6
    Join Date
    Mar 2007
    Posts
    3
    Qt products
    Qt4

    Default Re: problem in qt hello world programme

    Quote Originally Posted by patrik08 View Post
    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

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: problem in qt hello world programme

    So, the problem was solved? (Yes, you were missing the debug libs)
    J-P Nurmi

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.