Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Trying to learn qt
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
weirdo
Tux's lil' helper
Tux's lil' helper


Joined: 16 Apr 2002
Posts: 114
Location: Montreal/Quebec/Canada

PostPosted: Sun Jul 28, 2002 3:45 am    Post subject: Trying to learn qt Reply with quote

I am trying to learn qt. I am learning whit the trolltech tutorial at http://doc.trolltech.com/3.0/tutorial.html
I copied the hello world program in a hello.C files in a qt directory in my home directory. I tried compiling it whit g++ by doing
Code:
g++ hello.C -o hello

but this is the result
Code:
sh-2.05a$ g++ hello.C -o hello
hello.C:7: qapplication.h: No such file or directory
hello.C:8: qpushbutton.h: No such file or directory
sh-2.05a$

so i tryied
Code:
 locate qapplication.h

which told me the header files where in /usr/qt/3/include/
after changing the 2 #include line in the hello world code whit the full path to the header files(see the code next)
Code:
/****************************************************************
**
** Qt tutorial 1
**
****************************************************************/

#include </usr/qt/3/include/qapplication.h>
#include </usr/qt/3/include/qpushbutton.h>


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();
}

this is the answer g++ gave me
Code:
sh-2.05a$ g++ hello.C -o hello
In file included from /usr/qt/3/include/qobjectdefs.h:42,
                 from /usr/qt/3/include/qwindowdefs.h:43,
                 from /usr/qt/3/include/qwidget.h:42,
                 from /usr/qt/3/include/qdesktopwidget.h:42,
                 from /usr/qt/3/include/qapplication.h:42,
                 from hello.C:7:
/usr/qt/3/include/qglobal.h:595: qconfig.h: No such file or directory
In file included from /usr/qt/3/include/qobjectdefs.h:42,
                 from /usr/qt/3/include/qwindowdefs.h:43,
                 from /usr/qt/3/include/qwidget.h:42,
                 from /usr/qt/3/include/qdesktopwidget.h:42,
                 from /usr/qt/3/include/qapplication.h:42,
                 from hello.C:7:
/usr/qt/3/include/qglobal.h:654: qfeatures.h: No such file or directory

whats should i do now

p.s i try emerging qt again but it gave me the same thing
Back to top
View user's profile Send private message
Naan Yaar
Bodhisattva
Bodhisattva


Joined: 27 Jun 2002
Posts: 1549

PostPosted: Sun Jul 28, 2002 4:13 am    Post subject: Reply with quote

The site you refer to has tips on how to build this project using "qmake -project" and qmake.
http://doc.trolltech.com/3.0/tutorial1-01.html
If you follow those instructions, you will be able to compile without problems. Note: you need to remove the fully qualified header path in your #include statements.

That is:
Code:

#include </usr/qt/3/include/qapplication.h>
#include </usr/qt/3/include/qpushbutton.h>


need to be changed to:

Code:

#include <qapplication.h>
#include <qpushbutton.h>


Also, you may want to check out how the -I works with g++/gcc. You can see it being used when the makefile executes.
Back to top
View user's profile Send private message
weirdo
Tux's lil' helper
Tux's lil' helper


Joined: 16 Apr 2002
Posts: 114
Location: Montreal/Quebec/Canada

PostPosted: Sun Jul 28, 2002 4:31 am    Post subject: Reply with quote

ok i've folowed the tutorial guidline but i get an error here is the whole result of the make
Code:
sh-2.05a$ make
g++ -c -pipe -Wall -W -O2 -DQT_NO_DEBUG  -I/usr/qt/3/include -I/usr/qt/3/mkspecs/linux-g++ -o main.o main.cpp
g++  -o qt main.o    -L/usr/X11R6/lib -lXext -lX11 -lm
main.o: In function `main':
main.o(.text+0x1c): undefined reference to `QApplication::QApplication(int &, char **)'
main.o(.text+0x32): undefined reference to `QString::QString(char const *)'
main.o(.text+0x45): undefined reference to `QPushButton::QPushButton(QString const &, QWidget *, char const *)'
main.o(.text+0x67): undefined reference to `QString::shared_null'
main.o(.text+0x6f): undefined reference to `QString::shared_null'
main.o(.text+0x7c): undefined reference to `QStringData::deleteSelf(void)'
main.o(.text+0x8c): undefined reference to `QPushButton::resize(int, int)'
main.o(.text+0x96): undefined reference to `QApplication::setMainWidget(QWidget *)'
main.o(.text+0xa2): undefined reference to `QWidget::show(void)'
main.o(.text+0xab): undefined reference to `QApplication::exec(void)'
main.o(.text+0xb8): undefined reference to `QPushButton::~QPushButton(void)'
main.o(.text+0xc3): undefined reference to `QApplication::~QApplication(void)'
main.o(.text+0xf6): undefined reference to `QString::shared_null'
main.o(.text+0xfe): undefined reference to `QString::shared_null'
main.o(.text+0x10b): undefined reference to `QStringData::deleteSelf(void)'
main.o(.text+0x124): undefined reference to `QPushButton::~QPushButton(void)'
main.o(.text+0x13a): undefined reference to `QApplication::~QApplication(void)'
main.o: In function `QValueListPrivate<QString>::QValueListPrivate(void)':
main.o(.QValueListPrivate<QString>::gnu.linkonce.t.(void)+0x25): undefined reference to `QString::shared_null'
main.o(.QValueListPrivate<QString>::gnu.linkonce.t.(void)+0x2e): undefined reference to `QString::makeSharedNull(void)'
main.o: In function `QValueListPrivate<QString>::~QValueListPrivate(void)':
main.o(.gnu.linkonce.t._._t17QValueListPrivate1Z7QString+0x27): undefined reference to `QString::shared_null'
main.o(.gnu.linkonce.t._._t17QValueListPrivate1Z7QString+0x2f): undefined reference to `QString::shared_null'
main.o(.gnu.linkonce.t._._t17QValueListPrivate1Z7QString+0x3c): undefined reference to `QStringData::deleteSelf(void)'
main.o(.gnu.linkonce.t._._t17QValueListPrivate1Z7QString+0x69): undefined reference to `QString::shared_null'
main.o(.gnu.linkonce.t._._t17QValueListPrivate1Z7QString+0x71): undefined reference to `QString::shared_null'
main.o(.gnu.linkonce.t._._t17QValueListPrivate1Z7QString+0x7e): undefined reference to `QStringData::deleteSelf(void)'
main.o: In function `QValueListPrivate<QString>::insert(QValueListIterator<QString>, QString const &)':
main.o(.QValueListPrivate<QString>::gnu.linkonce.t.insert(QValueListIterator<QString>, QString const &)+0x27): undefined reference to `QString::QString(QString const &)'
main.o: In function `QValueListPrivate<QString>::QValueListPrivate(QValueListPrivate<QString> const &)':
main.o(.QValueListPrivate<QString>::gnu.linkonce.t.(QValueListPrivate<QString> const &)+0x25): undefined reference to `QString::shared_null'
main.o(.QValueListPrivate<QString>::gnu.linkonce.t.(QValueListPrivate<QString> const &)+0x2e): undefined reference to `QString::makeSharedNull(void)'
collect2: ld returned 1 exit status
make: *** [qt] Error 1
sh-2.05a$
Back to top
View user's profile Send private message
Naan Yaar
Bodhisattva
Bodhisattva


Joined: 27 Jun 2002
Posts: 1549

PostPosted: Sun Jul 28, 2002 4:53 am    Post subject: Reply with quote

It seems to work OK on my box. The second (link) line looks like:
Code:

g++  -o qqq main.o    -Wl,-rpath,/usr/qt/3/lib  -L/usr/qt/3/lib  -L/usr/X11R6/lib -lqt -lXext -lX11 -lm


You are missing the qt libraries and their path from your link line. You can probably edit the Makefile that qmake produces and change the line that says LIBS = ... to:
Code:

LIBS     = $(SUBLIBS)  -Wl,-rpath,$(QTDIR)/lib  -L$(QTDIR)/lib  -L/usr/X11R6/lib -lqt -lXext -lX11 -lm


I am not sure why qmake does not produce the library path.
Back to top
View user's profile Send private message
weirdo
Tux's lil' helper
Tux's lil' helper


Joined: 16 Apr 2002
Posts: 114
Location: Montreal/Quebec/Canada

PostPosted: Sun Jul 28, 2002 5:08 am    Post subject: Reply with quote

the g++ command you wrote works perfectly

I should learn more about gcc
Back to top
View user's profile Send private message
trythil
Tux's lil' helper
Tux's lil' helper


Joined: 06 Jun 2002
Posts: 123
Location: RHIT, Terre Haute, IN, USA

PostPosted: Sun Jul 28, 2002 8:40 am    Post subject: Reply with quote

The -I directive adds additional paths to search for system libraries. Thus, you could have added

-I/usr/qt/3/include

and have removed all those nasty directories in your #include directives (which is non-portable code anyway).

-L tells GCC to look in those directories for libraries that you choose to link against with -l.
Back to top
View user's profile Send private message
credmp
Apprentice
Apprentice


Joined: 02 Jul 2002
Posts: 207
Location: Netherlands

PostPosted: Tue Aug 06, 2002 7:50 am    Post subject: Reply with quote

With Qt one should always try to use the .pro files.... ie I use the following for one of my projects:

Code:

PROJECT               = Application
CONFIG               = warn_on debug qt
DEFINES               = QT_THREAD_SUPPORT
TARGET               = Application
TEMPLATE            = app

unix:LIBS            = -lqt-mt


Then run

Code:

qmake application.pro


which generates the Makefile with all the proper paths etc. the TEMPLATE directive is pretty crucial in this :)

-- Arjen
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum