LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-01-2002, 08:48 AM   #1
gurra
LQ Newbie
 
Registered: Sep 2001
Distribution: Flyinglinux
Posts: 12

Rep: Reputation: 0
Question compiling own QT apps


Hi!

I am playing with qt and wrote a program that looks like this:

main.cpp:

#include "qapplication.h"
#include "mainwindow.h"

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

MainWindow *mw = new MainWindow();
mw->setCaption("KDC");
mw->show();

app.connect(&app, SIGNAL(lastWindowClosed()), &app, SIGNAL(quit()));
return app.exec();
}




mainwindow.h:
g++ -I/usr/lib/qt3/include -c main.cpp
g++ -I/usr/lib/qt3/include -c mainwindow.cpp
g++ -o main main.o mainwindow.o -L/usr/lib/qt3/lib -L/usr/X11R6/lib/ -lqt -lX11 -lXext
mainwindow.o: In function `MainWindow::MainWindow(void)':
mainwindow.o(.text+0x1e): undefined reference to `MainWindow::QPaintDevice virtual table'
mainwindow.o(.text+0x25): undefined reference to `MainWindow virtual table'
collect2: ld returned 1 exit status
make: *** [kdc] Error 1
#ifndef classMainWindow
#define classMainWindow

#include "qmainwindow.h"
#include "qptrlist.h"
#include "qworkspace.h"

class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
~MainWindow();

private:
//QWorkspace *ws;
QWorkspace* ws;
};

#endif



mainwindow.cpp:

#include "mainwindow.h"
#include "qvbox.h"

MainWindow::MainWindow()
{
QVBox *vb = new QVBox(this);
vb->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
ws = new QWorkspace(vb);
ws->setScrollBarsEnabled(true);
setCentralWidget(vb);
}

Then I tried to compile this with a Makefile like this:

INCLUDEDIR = -I$(QTDIR)/include
LIBDIR = -L$(QTDIR)/lib -L/usr/X11R6/lib/
LIBS = -lqt -lX11 -lXext

kdc : main.o mainwindow.o
g++ -o main main.o mainwindow.o $(LIBDIR) $(LIBS)

main.o : main.cpp
g++ $(INCLUDEDIR) -c main.cpp

mainwindow.o : mainwindow.cpp
g++ $(INCLUDEDIR) -c mainwindow.cpp

but I always get this error:

g++ -I/usr/lib/qt3/include -c main.cpp
g++ -I/usr/lib/qt3/include -c mainwindow.cpp
g++ -o main main.o mainwindow.o -L/usr/lib/qt3/lib -L/usr/X11R6/lib/ -lqt -lX11 -lXext
mainwindow.o: In function `MainWindow::MainWindow(void)':
mainwindow.o(.text+0x1e): undefined reference to `MainWindow::QPaintDevice virtual table'
mainwindow.o(.text+0x25): undefined reference to `MainWindow virtual table'
collect2: ld returned 1 exit status
make: *** [kdc] Error 1

Does anybody know what I am doing wrong?
Please, help!
 
Old 09-01-2002, 08:53 AM   #2
gurra
LQ Newbie
 
Registered: Sep 2001
Distribution: Flyinglinux
Posts: 12

Original Poster
Rep: Reputation: 0
the code is supposed to look like this:

----- main.cpp: -------
#include "qapplication.h"
#include "mainwindow.h"

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

MainWindow *mw = new MainWindow();
mw->setCaption("KDC");
mw->show();

app.connect(&app, SIGNAL(lastWindowClosed()), &app, SIGNAL(quit()));
return app.exec();
}

---- mainwindow.h: ------
#ifndef classMainWindow
#define classMainWindow

#include "qmainwindow.h"
#include "qptrlist.h"
#include "qworkspace.h"

class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
~MainWindow();

private:
//QWorkspace *ws;
QWorkspace* ws;
};

#endif

---- mainwindow.cpp ---
#include "mainwindow.h"
#include "qvbox.h"

MainWindow::MainWindow()
{
QVBox *vb = new QVBox(this);
vb->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
ws = new QWorkspace(vb);
ws->setScrollBarsEnabled(true);
setCentralWidget(vb);
}


--- and the error message like this: ---
g++ -I/usr/lib/qt3/include -c main.cpp
g++ -I/usr/lib/qt3/include -c mainwindow.cpp
g++ -o main main.o mainwindow.o -L/usr/lib/qt3/lib -L/usr/X11R6/lib/ -lqt -lX11 -lXext
mainwindow.o: In function `MainWindow::MainWindow(void)':
mainwindow.o(.text+0x1e): undefined reference to `MainWindow::QPaintDevice virtual table'
mainwindow.o(.text+0x25): undefined reference to `MainWindow virtual table'
collect2: ld returned 1 exit status
make: *** [kdc] Error 1
 
Old 09-01-2002, 11:32 AM   #3
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
I think your problem is you aren't running moc before the compile.

Qt isn't pure C++, it also uses a meta-object compiler (moc) which you need to run before g++. Doing this manually is a pain; using qmake to do it for you is a lot easier. Look at the Trolltech docs for information on qmake. (I believe in Qt < 3 there is a similar program called tmake).

If you don't have any classes qith Q_OBJECT at the top of them, you don't need to run the moc.

Alex
 
Old 02-22-2003, 10:36 PM   #4
Penguinizer
LQ Newbie
 
Registered: Dec 2002
Location: Egypt
Distribution: Mandrake
Posts: 28

Rep: Reputation: 15
I'm Having the Same Exact Problem but how can I avoid getting these unexplained erros .

I'm using KDevelop where to add moc , Do I have to change the compiler command ??

when I paste down Tutorial Chapter 7 it works perfectly ????????????????????????????????????????

And If I wrote the exact same code it doesn't work
 
Old 02-23-2003, 11:50 AM   #5
Penguinizer
LQ Newbie
 
Registered: Dec 2002
Location: Egypt
Distribution: Mandrake
Posts: 28

Rep: Reputation: 15
Please Answer Me ?

I'm Stuck and I can't move ????
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling apps winterhunter Linux - Software 1 10-14-2005 08:11 PM
Compiling apps Jimbo99 Linux - Software 13 04-07-2005 05:41 AM
Compiling from sources - Launching Apps... ArthurDent Linux - Newbie 3 07-10-2004 08:57 AM
RedHat 8.0: compiling and installing apps artemis Linux - Distributions 2 02-26-2003 02:46 AM
Compiling OpenGL apps with H/W acceleration L33t_H4x0R Linux - Software 0 02-03-2003 10:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration