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();
}
#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();
}
To copy to clipboard, switch view to plain text mode
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).
Bookmarks