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
Forum Updated to NodeBB v4.3 + New Features

QT_WIDGETS_LIB

Scheduled Pinned Locked Moved General and Desktop
15 Posts 2 Posters 6.5k 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.
  • E Offline
    E Offline
    Exotic_Devel
    wrote on last edited by
    #4

    I changed the code of test for a unique cpp file, as is done in the QTest documentation .
    I am now getting an error of type conversion.

    @In file included from /opt/Qt/5.3/gcc_64/include/QtTest/qtest.h:293:0,
    from /opt/Qt/5.3/gcc_64/include/QtTest/QtTest:7,
    from dynamicqtwidgetstest.cpp:23:
    /opt/Qt/5.3/gcc_64/include/QtTest/qtestsystem.h: In function ‘bool QTest::qWaitForWindowActive(QWidget*, int)’:
    /opt/Qt/5.3/gcc_64/include/QtTest/qtestsystem.h:122:56: error: cannot convert ‘QWindow*’ to ‘QWidget*’ for argument ‘1’ to ‘bool QTest::qWaitForWindowActive(QWidget*, int)’
    return qWaitForWindowActive(window, timeout);
    ^
    /opt/Qt/5.3/gcc_64/include/QtTest/qtestsystem.h: In function ‘bool QTest::qWaitForWindowExposed(QWidget*, int)’:
    /opt/Qt/5.3/gcc_64/include/QtTest/qtestsystem.h:129:57: error: cannot convert ‘QWindow*’ to ‘QWidget*’ for argument ‘1’ to ‘bool QTest::qWaitForWindowExposed(QWidget*, int)’
    return qWaitForWindowExposed(window, timeout);
    ^
    @

    "My Makefile":http://paste.ubuntu.com/7794975/

    test code

    @/*

    • dynamicqtwidgetstest.cpp
    • This file is part of dynamicqtwidgets.so
    • Copyright (C) 2014 - Matheus Saraiva
    • dynamicqtwidgets.so is free software; you can redistribute it and/or modify
    • it under the terms of the GNU General Public License as published by
    • the Free Software Foundation; either version 2 of the License, or
    • (at your option) any later version.
    • dynamicqtwidgets.so is distributed in the hope that it will be useful,
    • but WITHOUT ANY WARRANTY; without even the implied warranty of
    • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    • GNU General Public License for more details.
    • You should have received a copy of the GNU General Public License
    • along with dynamicqtwidgets.so. If not, see http://www.gnu.org/licenses/.
      */

    define QT_WIDGETS_LIB

    #include <QtCore/QString>
    #include <QtTest/QtTest>
    #include "dynamicqtwidgets.hpp"

    class DynamicQtWidgetsTest : public QObject
    {
    Q_OBJECT

    private Q_SLOTS:
    void testCreateWidget();
    void testCreateWidget_data();
    };

    void DynamicQtWidgetsTest::testCreateWidget()
    {
    QFETCH(QString, file_ui);
    QFETCH(bool, widget);

    DynamicQtWidgets dynawidg(file_ui); // DynamicQtWidgets object
    QWidget *widtest = dynawidg.createWidget();
    QCOMPARE(widtest->isWidgetType(), widget); // Compare DynamicQtWidgets::createWidget() return with QWidget type
    delete widtest;
    }

    void DynamicQtWidgetsTest::testCreateWidget_data()
    {
    QTest::addColumn<QString>("file_ui");
    QTest::addColumn<bool>("widget");

    QTest::newRow("Valid File") << "test.ui" << true; // Valid File
    QTest::newRow("Inexistent File") << "inexistent.ui" << true; // Inexistent File
    QTest::newRow("Invalid File") << "test_text.ui" << true; // Invalid File
    QTest::newRow("Empty Ui File") << "testempty.ui" << true; // Empty File
    }

    QTEST_MAIN(DynamicQtWidgetsTest)
    #include "dynamicqtwidgetstest.moc"@

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

      If i remove "#define QT_WIDGETS_LIB" initial problem back

      If i use QT_GUI_LIB return: undefined reference to symbol '_ZN15QGuiApplicationC1ERiPPci' error
      error adding symbols: DSO missing from command line

      @#ifndef QT_GUI_LIB

      define QT_GUI_LIB

      #endif

      #include <QtCore/QString>
      #include <QtTest/QtTest>
      #include "dynamicqtwidgets.hpp"

      class DynamicQtWidgetsTest : public QObject
      {
      Q_OBJECT

      private Q_SLOTS:
      void testCreateWidget();
      void testCreateWidget_data();
      };

      void DynamicQtWidgetsTest::testCreateWidget()
      {
      QFETCH(QString, file_ui);
      QFETCH(bool, widget);

      DynamicQtWidgets dynawidg(file_ui); // DynamicQtWidgets object
      QWidget *widtest = dynawidg.createWidget();
      QCOMPARE(widtest->isWidgetType(), widget); // Compare DynamicQtWidgets::createWidget() return with QWidget type
      delete widtest;
      }

      void DynamicQtWidgetsTest::testCreateWidget_data()
      {
      QTest::addColumn<QString>("file_ui");
      QTest::addColumn<bool>("widget");

      QTest::newRow("Valid File") << "test.ui" << true; // Valid File
      QTest::newRow("Inexistent File") << "inexistent.ui" << true; // Inexistent File
      QTest::newRow("Invalid File") << "test_text.ui" << true; // Invalid File
      QTest::newRow("Empty Ui File") << "testempty.ui" << true; // Empty File
      }

      #include "dynamicqtwidgetstest.moc"
      QTEST_MAIN(DynamicQtWidgetsTest)@

      1 Reply Last reply
      0
      • 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