Transition qt4.6 to qt5.7 with Erorr token



  • I am transition from Qt 4.x to Qt 5 : I have Add this on my *.pro file: "QT += core gui widgets" as well "Change all instances of #include <QtGui> to #include <QtWidgets>.

    I am getting an Error:expected class-name before '{' token line 95 qimage.h. I am not using qimage.h or any QPaintDevices.


  • Moderators

    @liondavid Is this the only error you get?
    Can you show the code where this error occur?
    Did you delete the build directory, run qmake and rebuild then?



  • Errors I am getting are in qimage.h, qpixmap.h, qfont.h, qfontmetrics.h, qwidget.h, qpainter.h, qstylepainter.h, All have Error Token. few repeat come out saying QpaintDevice and Qpainter has not been declared. few repeat come out as Qwidget error 'WID' does not name a type. When only talk about my code when it say:

    Error: expected ';' before '' token In file included from /usr/include/qt5/QtWidgets/QtWidgets:73, from MultiPingDlg.h;14 and from main.cpp;6 in constructor 'QStylePainter::QStylePainter(QWidget); candidaates are bool QStylepainter::begin(QWidget*) note: bool Qstylepainter being (QPaintDevice*, QWidget*) in member function bool QStylePainter::begin(QWidget*):
    No matching function for call to 'QStylePainter::begin(QWidget*&, QWidget*&)

    MultiPingDlg.h is mainwindow.h

    Yes, I did delete the build directory and did qmake and rebuid.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You shouldn't use the module includes. They will pull in every header of their respective module which will make the build longer for no benefits.



  • What do you mean by don't use the module includes? Do you mean what I just add on my pro file, for example; Qt +=core gui widgets.


  • Lifetime Qt Champion

    I mean don't use #include <QtGui> or #include <QtWidgets>. Include what you are using: #include <QWidget>, #include <QImage> etc.

    By the way, QtGui has not been renamed QtWidgets, the widget related classes have been moved to the QtWidgets module hence your errors.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.