Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Problem with Executing Example [SOLVED]
Forum Updated to NodeBB v4.3 + New Features

Problem with Executing Example [SOLVED]

Scheduled Pinned Locked Moved Installation and Deployment
6 Posts 3 Posters 2.9k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SidRama
    wrote on last edited by SidRama
    #1

    I have installed QT from source and everything seems fine. This is the test code I am trying to run:

    #include <QApplication>
    #include <QTextEdit>

        int main(int argv, char **args)
        {
            QApplication app(argv, args);
    
            QTextEdit textEdit;
            textEdit.show();
    
            return app.exec();
       }
    

    I saved this in a folder called QTCode. I then used qmake -project and qmake. However, when I finally call make I get the following error:

    g++ -Wl,-O1 -Wl,-rpath,/usr/local/Qt-5.4.1/lib -o QTCode test.o -L/usr/local/Qt-5.4.1/lib -lQt5Gui -lQt5Core -lGL -lpthread
    test.o: In function main': test.cpp:(.text.startup+0x27): undefined reference to QApplication::QApplication(int&, char**, int)'
    test.cpp:(.text.startup+0x31): undefined reference to QTextEdit::QTextEdit(QWidget*)' test.cpp:(.text.startup+0x39): undefined reference to QWidget::show()'
    test.cpp:(.text.startup+0x3e): undefined reference to QApplication::exec()' test.cpp:(.text.startup+0x49): undefined reference to QTextEdit::~QTextEdit()'
    test.cpp:(.text.startup+0x51): undefined reference to QApplication::~QApplication()' test.cpp:(.text.startup+0x68): undefined reference to QApplication::~QApplication()'
    test.cpp:(.text.startup+0x7b): undefined reference to `QTextEdit::~QTextEdit()'
    collect2: error: ld returned 1 exit status
    make: *** [QTCode] Error 1

    I am not sure if this is a problem with installation. I would be grateful for any help! Thank you!

    K 1 Reply Last reply
    0
    • S SidRama

      I have installed QT from source and everything seems fine. This is the test code I am trying to run:

      #include <QApplication>
      #include <QTextEdit>

          int main(int argv, char **args)
          {
              QApplication app(argv, args);
      
              QTextEdit textEdit;
              textEdit.show();
      
              return app.exec();
         }
      

      I saved this in a folder called QTCode. I then used qmake -project and qmake. However, when I finally call make I get the following error:

      g++ -Wl,-O1 -Wl,-rpath,/usr/local/Qt-5.4.1/lib -o QTCode test.o -L/usr/local/Qt-5.4.1/lib -lQt5Gui -lQt5Core -lGL -lpthread
      test.o: In function main': test.cpp:(.text.startup+0x27): undefined reference to QApplication::QApplication(int&, char**, int)'
      test.cpp:(.text.startup+0x31): undefined reference to QTextEdit::QTextEdit(QWidget*)' test.cpp:(.text.startup+0x39): undefined reference to QWidget::show()'
      test.cpp:(.text.startup+0x3e): undefined reference to QApplication::exec()' test.cpp:(.text.startup+0x49): undefined reference to QTextEdit::~QTextEdit()'
      test.cpp:(.text.startup+0x51): undefined reference to QApplication::~QApplication()' test.cpp:(.text.startup+0x68): undefined reference to QApplication::~QApplication()'
      test.cpp:(.text.startup+0x7b): undefined reference to `QTextEdit::~QTextEdit()'
      collect2: error: ld returned 1 exit status
      make: *** [QTCode] Error 1

      I am not sure if this is a problem with installation. I would be grateful for any help! Thank you!

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @SidRama
      Hi and welcome to devnet

      There is actually an example for QTextEdit available.

      What do you have in your .pro file?

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SidRama
        wrote on last edited by SidRama
        #3

        Hi!
        Actually, the above program is from an example:
        http://doc.qt.io/qt-4.8/gettingstartedqt.html

        This is the contents of the .pro file:

        TEMPLATE = app
        TARGET = QTCode
        INCLUDEPATH += .
        #Input
        SOURCES += test.cpp

        In the folder I have a Makefile, a QTCode.pro file, test.cpp and test.o

        Thank you!

        K 1 Reply Last reply
        0
        • S SidRama

          Hi!
          Actually, the above program is from an example:
          http://doc.qt.io/qt-4.8/gettingstartedqt.html

          This is the contents of the .pro file:

          TEMPLATE = app
          TARGET = QTCode
          INCLUDEPATH += .
          #Input
          SOURCES += test.cpp

          In the folder I have a Makefile, a QTCode.pro file, test.cpp and test.o

          Thank you!

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @SidRama
          You should use the new example. There are only a couple of differences between Qt4 and Qt5. However, a major difference is probably in the .pro file. That may explain your problem.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi and welcome to devnet,

            @koahnig is right, with Qt 5, the widgets have now their own module separated from gui, so the pro files from Qt 4 won't have QT += widgets that is needed to compile with Qt 5.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SidRama
              wrote on last edited by
              #6

              Hi!
              Thank you so much! It turns out that I hadn't installed QT properly and the CLASSPATH was messed up.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved