Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Need help in solving the undefined reference error for qt5



  • Hi All
    I am trying to run a code with the QT5 library
    I have the following code

    #include <QtWidgets/QWidget>
    2 #include <QtWidgets/QApplication>
    3 #include <QtWidgets/QPushButton>
    4 int main(int argc, char *argv[])
    5 {
    6 QApplication app(argc, argv);
    7
    8 QPushButton hello("Hello world!");
    9 hello.resize(100, 30);
    10
    11 hello.show();
    12 return app.exec();
    13 }
    ~
    I have a following .pro file and

    ######################################################################

    Automatically generated by qmake (3.1) Thu Oct 11 10:04:00 2018

    ######################################################################

    TEMPLATE = app
    TARGET = Qt_Examples
    INCLUDEPATH += .
    QT += core gui
    @QT += widgets@

    The following define makes your compiler warn you if you use any

    feature of Qt which has been marked as deprecated (the exact warnings

    depend on your compiler). Please consult the documentation of the

    deprecated API in order to know how to port your code away from it.

    DEFINES += QT_DEPRECATED_WARNINGS
    following is .pro file

    You can also select to disable deprecated APIs only up to a certain version of Qt.

    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

    Input

    SOURCES += main.cpp
    ~

    I am getting following e

    undefined reference to QWidget::show()' main.o:(.qtversion[qt_version_tag]+0x0): undefined reference toqt_version_tag'
    main.o: In function QTypedArrayData<unsigned short>::deallocate(QArrayData*)': qt594_20180627/debug/linux_x86_64/include/QtCore/qarraydata.h:237: undefined reference toQArrayData::deallocate(QArrayData*, unsigned long, unsigned long)'
    collect2: error: ld returned 1 exit status


  • Lifetime Qt Champion

    Hi
    If you make a empty default GUI project , does that run ?
    How did you install Qt5 ?


  • Lifetime Qt Champion

    Hi,

    To add to @mrjj, did you re-run qmake after adding QT += widgets to your .pro file ?



  • @mrjj

    What is empty default project can u please elaborate



  • @SGaist

    Yes I did . Any hints to solve the problem



  • Hi, perhaps there's a problem because this is not a Qt5 program, it's at least [10 years old example](https://doc.qt.io/archives/4.3/tutorial-t1.html

    You could try what @mrjj suggests: start Qt Creator, select File, New File or Project, select Application, select Qt Widgets Application, don't change anything, just try to run it.



  • I am running in linux and do not have a Qt Creator. COuld you generate a code for me for Empty Gui Project that I can resue in QMake in linux



  • I am also running Linux but I have Qt Creator, makes it easier to use Qt. You can download it for free here



  • which version of Qt creator is compatible with Qt5



  • I have 4.7.1 and it works fine.
    0_1539296832925_Screenshot from 2018-10-12 00-26-32.png


Log in to reply