Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT_WIDGETS_LIB
Qt 6.11 is out! See what's new in the release blog

QT_WIDGETS_LIB

Scheduled Pinned Locked Moved General and Desktop
15 Posts 2 Posters 7.2k Views 1 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.
  • A Offline
    A Offline
    andreyc
    wrote on last edited by
    #6

    @
    dynamicqtwidgetstest.moc: dynamicqtwidgetstest.cpp
    moc dynamicqtwidgetstest.cpp -o ../mocs/dynamicqtwidgetstest.moc
    @
    Is it possible that you have another moc in the $PATH ?

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Exotic_Devel
      wrote on last edited by
      #7

      No, just the mocfile that was generated by the compilation line you quoted.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andreyc
        wrote on last edited by
        #8

        I meant an executable. Do you have another Qt installed?
        You calling moc in Makefile without full path so if you have other moc in the $PATH then it may be called instead.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #9

          I created a test case using your files. And got the error you are describing.
          I think it is related to the fact that you don't use qmake and did not provided all necessary flags.
          If you have to avoid qmake (why?) then try to create an empty Qt Test project in QtCreator, run qmake and compare the include and link flags.

          1 Reply Last reply
          0
          • E Offline
            E Offline
            Exotic_Devel
            wrote on last edited by
            #10

            Unsuccessfully

            I followed his advice, I created a test project with QtCreator and looked flags which he is using. I Added the same flags in my compile line, but the error continues.

            I added flags:

            -pipe -g- W -D_REENTRANT

            I also changed the flag-fPIC to -fPIE

            This is my first deep contact with C + + and Qt, and I not want to become dependent of QtCreator.
            But pareque that Qt does not encourage more manual programming.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andreyc
              wrote on last edited by
              #11

              Here is my Makefile that worked for me
              @
              #compiler
              CXX = g++

              #path for Qt
              QT = /home/user/Qt5.3.1/5.3/gcc_64

              #path for libs Qt
              LIBSQT = -L$(QT)/lib/

              #path for includes Qt
              INCSQT = -I$(QT)/include/

              #path for include taget test
              INCOBJTEST = -I../src

              #path for moc files
              MOCS = -I../mocs

              #path for taget test
              OBJTEST = -L../build

              #All includes
              INCPATH = -I$(QT)/mkspecs/linux-g++ -I$(QT)/include/QtWidgets -I$(QT)/include/QtTest -I$(QT)/include/QtGui -I$(QT)/include/QtCore -I.
              INCS = $(INCPATH) $(INCSQT) $(MOCS) $(INCOBJTEST) -DQT_WIDGETS_LIB -DQT_TESTLIB_LIB -DQT_GUI_LIB -DQT_CORE_LIB

              #All libs
              LIBS = $(LIBSQT) -L$(QT)/lib -lQt5Widgets -lQt5Test -lQt5Gui -lQt5Core -lGL -lpthread

              #final target
              DynamicQtWidgetsTest: dynamicqtwidgetstest.moc dynamicqtwidgetstest.cpp
              $(CXX) -Wall -fPIC -oDynamicQtWidgetsTest $(word 2,$^) $(INCS) -Wl,-rpath,/home/user/Qt5.3.1/5.3/gcc_64 -Wl,-rpath,/home/user/Qt5.3.1/5.3/gcc_64/lib $(LIBS)

              #Generate moc file
              dynamicqtwidgetstest.moc: dynamicqtwidgetstest.cpp
              $(QT)/bin/moc -DQT_WIDGETS_LIB -DQT_TESTLIB_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_TESTCASE_BUILDDIR="/home/user/tmp/test_forum" -I$(QT)/mkspecs/linux-g++ -I/home/user/tmp/qmake_test/untitled1 -I$(QT)/include -I$(QT)/include/QtWidgets -I$(QT)/include/QtTest -I$(QT)/include/QtGui -I$(QT)/include/QtCore -I. dynamicqtwidgetstest.cpp -o dynamicqtwidgetstest.moc

              clean:
              rm -f dynamicqtwidgetstest.moc DynamicQtWidgetsTest
              @

              1 Reply Last reply
              0
              • E Offline
                E Offline
                Exotic_Devel
                wrote on last edited by
                #12

                I chose create the main manually, I had no success, even after seeing your makefile.
                I put the "project":https://github.com/matheusssilva/DynamicQtWidgets on github, there you can have a full view of it.
                Maybe so you can tell what is missing for QTEST_MAIN work

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andreyc
                  wrote on last edited by
                  #13

                  I've modified three files to make your project buildable and runable

                  • src/Makefile
                    @
                    #compiler
                    CXX = g++

                  #path for Qt
                  QT = /opt/Qt/5.3/gcc_64

                  #path for libs Qt
                  LIBSQT = -L$(QT)/lib/

                  #path for includes Qt
                  INCSQT = -I$(QT)/include/

                  #generate final lib
                  ../build/libdynamicqtwidgets.so: ../build/dynamicqtwidgets.o
                  $(CXX) -Wall -shared -o ../build/libdynamicqtwidgets.so $< $(LIBSQT) -lQt5Core -lQt5Widgets -lQt5UiTools

                  #generate dynamicqtwidgets.o
                  ../build/dynamicqtwidgets.o: dynamicqtwidgets.cpp dynamicqtwidgets.hpp dynamicqtwidgets_global.hpp
                  $(CXX) -Wall -c -fPIC -o ../build/dynamicqtwidgets.o $< $(INCSQT)
                  @

                  • tests/Makefile
                    @
                    #compiler
                    CXX = g++

                  #path for Qt
                  QT = /opt/Qt/5.3/gcc_64

                  #path for libs Qt
                  LIBSQT = -L$(QT)/lib/

                  #path for includes Qt
                  INCSQT = -I$(QT)/include/

                  #path for include taget test
                  INCOBJTEST = -I../src

                  #path for moc files
                  MOCS = -I../mocs

                  #path for taget test
                  OBJTEST = -L../build

                  #All includes
                  INCS = $(INCSQT) $(MOCS) $(INCOBJTEST) -I.

                  #All libs
                  LIBS = $(LIBSQT) $(OBJTEST) -L$(QT)/lib -lQt5Widgets -lQt5Test -lQt5Gui -lQt5Core -lGL -lpthread

                  #final target
                  ../build/Test: ../mocs/dynamicqtwidgetstest.moc main.cpp dynamicqtwidgetstest.cpp dynamicqtwidgetstest.hpp
                  $(CXX) -Wall -fPIC -o ../build/Test $(word 2,$^) $(word 3,$^) $(INCS) -Wl,-rpath,'$$ORIGIN' $(LIBS) -ldynamicqtwidgets

                  #Generate moc file
                  ../mocs/dynamicqtwidgetstest.moc: dynamicqtwidgetstest.hpp
                  $(QT)/bin/moc $< -o ../mocs/dynamicqtwidgetstest.moc
                  @

                  • tests/main.cpp
                    @
                    #include "dynamicqtwidgetstest.hpp"
                    #include <QtWidgets/QApplication>

                  int main(int argc, char *argv[])
                  {
                  QApplication app(argc, argv);

                  DynamicQtWidgetsTest tests;
                  QTest::qExec(&tests, argc, argv);

                  return 0;
                  }
                  @

                  [EDIT] I replaced '@' character in the Makefiles to make qt-project source code parses happy.

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    Exotic_Devel
                    wrote on last edited by
                    #14

                    Thanks bro. I wanted to use QTEST_MAIN but Qt does not document the use of QT_WIDGETS_LIB without qmake.

                    Thanks for the tip of the main.cpp, I sought a way to finalize the main after test. Could not remember the old 'return 0'.
                    As for the '@', did not understand what you say.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andreyc
                      wrote on last edited by
                      #15

                      [quote author="Exotic_Devel" date="1405550468"]I wanted to use QTEST_MAIN but Qt does not document the use of QT_WIDGETS_LIB without qmake.[/quote]

                      qmake adds a -DQT_WIDGETS_LIB option to g++ command. As well as some other defines like -DQT_TESTLIB_LIB -DQT_GUI_LIB -DQT_CORE_LIB

                      See my previous Makefile example.

                      You can use QTEST_MAIN just add these options to g++ command line.
                      But if you need to make your test multi-platform then you need to investigate what qmake does for Visual Studio and clang. I think clang has the same command line as g++.

                      And for that reason (multi-platform) qmake is very handy.

                      [quote author="Exotic_Devel" date="1405550468"]
                      As for the '@', did not understand what you say.[/quote]
                      Your original Makefiles contained '$@' as a parameter for -o option in g++ and moc. This website parser uses '@' as source code tag and does not produce nice looking Makefile.
                      So I replaced all occurrences of '$@' with file names.

                      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