View Full Version : Can't Compile Tutorial 7

8th February 2006, 13:57
Hi, I've been compiling all the tutorials up to now, and snooping around it. But tutorial 7 (Qt Assistant - Tutorials - T7) doesn't compile.

It's the first tutorial that moves to multiple files, and it's the linker that can't compile.

Switching to target: default
Compiling: main.cpp
Compiling: lcdrange.cpp
Linking executable: C:\Projects\QTProjects\Tut1\tut1.exe
.objs\lcdrange.o:lcdrange.cpp:(.text+0x172): undefined reference to `vtable for LCDRange'
.objs\lcdrange.o:lcdrange.cpp:(.text+0x17e): undefined reference to `vtable for LCDRange'
.objs\lcdrange.o:lcdrange.cpp:(.text+0x4cc): undefined reference to `vtable for LCDRange'
.objs\lcdrange.o:lcdrange.cpp:(.text+0x4d8): undefined reference to `vtable for LCDRange'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 4 seconds)
0 errors, 0 warnings

Can anybody help me?

I have a bad feeling I've only been using Code::Blocks and not Qt before this.

8th February 2006, 14:12

I need to be in command prompt and go
qmake -project

But how can I get code::blocks to do that when I click compile?

8th February 2006, 15:15
Ok, try this.
Do this once:

Unzip the attachement to %HOMEPATH%\.Codeblocks
Restart Codeblocks
Menu > Settings > Compiler
Select Other tab
Set Build method to Work with Makefiles (GNU "make" required)
(Optional) Set Logging to Full command line
Menu > Tools > Configure tools...
Add the first tool

Name: Create QT Project file
Executable: Path to qmake.exe
Parameters: -o Makefile
Working directory: ${PROJECT_DIR}

Add the second tool

Name: Create Makefile
Executable: Path to qmake.exe
Parameters: leave empty
Working directory: ${PROJECT_DIR}

For each of your new QT Projects do the following:

Menu > File > New Project...
Select User Templates tab
Choose Cesar's QT Application
After adding new *.cpp, *.h files don't forget to

Menu > Tools > Create QT Project file
Menu > Tools > Create Makefile

8th February 2006, 15:34
Some more comments:
The name of the template depends on the name of the directory, which contains the *.cbp project template. In this case it is "Cesar's QT Application". You might want change it to something reasonable :).
The *.cbp file is plain XML file so it could be edited manually.
Now I'm looking for the fine way to include diferent QT modules while building the *.pro file. For now, you should change the Tool "Create QT Project file" and add QT+="sql network" to the options, to make use of sql and network modules respectively... Any ideas how to improove this approach?

8th February 2006, 15:58
Would you care giving this (http://forums.codeblocks.org/index.php?topic=2253.0) a try? Still pre-alpha I'm afraid but I'm working on it ;)

9th February 2006, 12:33
Still can't compile 7 or 8...


9th February 2006, 14:05
Could you, please, post something more informative? Any compilation/linking errors, the steps you've done to achive them, etc. Your post gives no information about the reason of your problem.

9th February 2006, 14:14
Sorry :)

Well, the results are still the same as it were earlier. So nothing's changed.

On both the projects.

But I could redo them from scratch again (using your Code::Blocks template, and check if they run again). But I don't have time for the next while...


9th February 2006, 14:31
That's ok, keep trying, when you find some spare time :)
But keep in mind, that qmake -project scans the current directory, all its sub-directories and adds the files it found to the project file. So all the *.o files left from the previous compilation attempts will occasionally get to the resulting Makefile. This may lead to broken dependencies, etc, etc...

9th February 2006, 14:57
Did you remember to add the Q_OBJECT macro to the class definition?
Did you split the class into two files (header and implementation)?

9th February 2006, 15:06
Yes, I did add the Q_OBJECT macro thingy to the file. But I haven't "rebooted" the whole application and restarted from scratch. :)

I'll do that when time permits.