QT_WIDGETS_LIB
-
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_OBJECTprivate 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)@ -
@
dynamicqtwidgetstest.moc: dynamicqtwidgetstest.cpp
moc dynamicqtwidgetstest.cpp -o ../mocs/dynamicqtwidgetstest.moc
@
Is it possible that you have another moc in the $PATH ? -
No, just the mocfile that was generated by the compilation line you quoted.
-
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. -
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. -
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. -
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.mocclean:
rm -f dynamicqtwidgetstest.moc DynamicQtWidgetsTest
@ -
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 -
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.
- src/Makefile
-
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. -
[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.
14/15