PDA

View Full Version : Cannot build diagram example under Windows 7,incomplete QGraphicsItem ckass



aheirich
18th December 2010, 05:41
This is my first time with Qt and I am trying to build the Diagram example from chapter 8 of 'C++ Gui Programming with Qt 4'. I am using 32 bit Windows 7 with the latest Qt just downloaded, open source model. I have Cygwin with mingw. I installed Qt in the usual way using the installer with all defaults selected.

The first problem I had was that qmake produced a Makefile.Debug that referenced -lmingw32 without also including <qt>/mingw/lib in the library search path. This caused the link step to fail with undefined library mingw32. I fixed this by adding

LIBS += -L'C:/Qt/2010.05/mingw/lib' -lmingw32

to the end of diagram.pro. Now the link step complains about incomplete classes in QtGui, specifically QGraphicsItem. Here is the output from the link step:

g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug/diagram.exe debug/diagramwindow.o debug/link.o debug/main.o debug/node.o debug/propertiesdialog.o debug/moc_diagramwindow.o debug/moc_propertiesdialog.o debug/qrc_resources.o -L'c:/Qt/2010.05/qt/lib' -lmingw32 -lqtmaind -LC:/Qt/2010.05/mingw/lib -lmingw32 -lQtGuid4 -lQtCored4
debug/diagramwindow.o:/home/aheirich/Desktop/editor/diagram/diagramwindow.cpp:275: undefined reference to `typeinfo for QGraphicsItem'
debug/diagramwindow.o:/home/aheirich/Desktop/editor/diagram/diagramwindow.cpp:265: undefined reference to `typeinfo for QGraphicsItem'
debug/diagramwindow.o:/home/aheirich/Desktop/editor/diagram/diagramwindow.cpp:285: undefined reference to `typeinfo for QGraphicsItem'
debug/diagramwindow.o:/home/aheirich/Desktop/editor/diagram/diagramwindow.cpp:286: undefined reference to `typeinfo for QGraphicsItem'
debug/diagramwindow.o:/home/aheirich/Desktop/editor/diagram/diagramwindow.cpp:57: undefined reference to `typeinfo for QGraphicsItem'
debug/link.o:link.cpp:(.rdata$_ZTI4Link typeinfo for Link]+0x8): undefined reference to `typeinfo for QGraphicsLineItem'
...


The undefined reference to 'typeinfo for c' means that class c contains virtual functions for which no definitions were found. I looked inside class QGraphicsItem and it certainly has many non-pure virtual functions so this may be true. I did not try to match up the definitions in QGraphicsItem.cpp so I didn't identify which functions were at fault. This simply should not be happening, or everyone would be having this problem using QGraphicsItem????

Is this a known problem? A problem only under Windows 7?

Added after 8 minutes:

Some further info. I tried #including each of the missing classes in the source files referred to in the error messages, for example in diagramwindow.cpp I added
#include <QGraphicsItem>
This did not solve the problem.

Added after 50 minutes:

Just to factor things further: I eliminated most of the contents of diagramwindow.cpp as shown below. This removes the diagram example from being a factor, this simply invokes a Qt class in a dynamic_cast. The error messages correspond to the two dynamic_cast statements below:



#include <QGraphicsItem>
#include <QtGui>

#include "diagramwindow.h"
#include "link.h"
#include "node.h"
#include "propertiesdialog.h"

#if 0
...
#endif////remove this

DiagramWindow::NodePair DiagramWindow::selectedNodePair() const
{
QList<QGraphicsItem *> items = scene->selectedItems();
if (items.count() == 2) {
Node *first = dynamic_cast<Node *>(items.first());
Node *second = dynamic_cast<Node *>(items.last());
if (first && second)
return NodePair(first, second);
}
return NodePair();
}


The example seems to show that you cannot use a QGraphicsItem * in a dynamic_cast,but this seems impossible for two reasons: 1. it means that QtGui is fundamentally broken; 2. this diagram example presumably used to work under Qt 4 (since it is included with the book for Qt 4).

franz
18th December 2010, 07:57
Try using qgraphicsitem_cast<>() instead of dynamic cast. This seems an rtti issue to me.

wysota
18th December 2010, 08:47
I'd say you built Qt without rtti support.

aheirich
18th December 2010, 17:49
I didn't build Qt, I installed it from the download. I'll have to read about rtti.
thanks

aheirich
19th December 2010, 05:38
update: the problem is definitely that the Open Source version of Qt on Windows is built without rtti support. There is no way to build the example program (chapter 8 diagram) without rtti. So I tried to build Qt from sources on windows. What a disaster. Suffice it to save I will save you a couple of paragraphs to conclude that I have given up on the Open Source Qt for Windows, it is not quality-assured enough. Building it doesn't work, in myriad ways. And without rtti I cannot use it.

On to the mac. But I am having problems there too! But that is another thread.

Added after 37 minutes:

All is well on the Mac, so I will continue work there. Windows has too many problems.

wysota
19th December 2010, 08:52
So I tried to build Qt from sources on windows. What a disaster. Suffice it to save I will save you a couple of paragraphs to conclude that I have given up on the Open Source Qt for Windows, it is not quality-assured enough. Building it doesn't work, in myriad ways. And without rtti I cannot use it.
I will have to check that but I think rtti should be enabled by default. As for building Qt, I have never had any serious problems with it. Maybe if you tell us what is wrong, we would be able to help you.

aheirich
3rd January 2011, 05:33
Well, I found that many problems were because I was trying to build under Cygwin. I didn't know about the mingw32 prompt. Right now it is building for me, keep fingers crossed. Then I will see if I can build the diagram example.

aheirich
3rd January 2011, 07:39
Yes it builds the example and it runs. Thanks to mingw32.