How can I integrate an existing Qt project in another Qt project
-
Hello,
I would like to integrate an existing Qt project in another Qt project. I thought about a solution via libs (libaries).
The existing Qt project is the QtFirebase Example. When it exists a simple method, for example with libs or other, I'm grateful for comments. Otherwise I know that you can subdivide via subdir, but I would need a step by step statement. -
-
Well, I followed the instructions, but it did not really help me. To clarify again, my point is to include push notifications in an existing Qt project. I've done the QtFirebase example and I can get push notifications. Now I would like to integrate this functionality into another project. As mentioned earlier, it would be best if I clicked "Add to Library" within another project and the push notification feature is added.
Surely there must be a possibility, I am convinced of that. Request for feedback.
-
@Robin-Hood said in How can I integrate an existing Qt project in another Qt project:
I've done the QtFirebase example and I can get push notifications.
Then do it like in that example.
What exactly is the problem? -
Well in the QtFirebase Example project this functionality is included from the beginning. So the whole C ++ files (for qtfirebasemessaging) as well as the platform files (for Android and iOS) are embedded within the whole folder structure. If I want to include these push notifications in a new project, then I do not want to add the individual files and customize my folders and thus all my previous project. I would like to include this feature (push notifications) as a small part in my previous project. It would be best to add this functionality via "Add library". Do you know, what is my problem now?
-
@Robin-Hood said in How can I integrate an existing Qt project in another Qt project:
Do you know, what is my problem now?
No, I don't.
I already posted links explaining how to create libraries and how to use them.
You answered that it didn't help you, but you did not tell what exactly is the problem with creating a shared library. -
Soooo ...
I have some old project (DataSaveModel). In it, I want to include the feature (push notifications), so this app should get push notifications from FCM (Firebase Cloud Messsaging). DataSaveModel is in the subdirsProject (test). I have worked through the tutorial Creating Shared Libraries and Adding Libraries to Projects and unfortunately did not reach my goal. For me it is not easy, what exactly is the problem or why it does not work (compiler shows no error). For this reason I have attached several screenshots to the comment. Please look at the pictures.
I hope you or anyone else can tell me what's wrong.
-
On the last picture you can see that I had tested through the console output, if he goes through the command. I do not get console output unfortunately. For this reason, I think that I do not even go into the header file. The acquaintance has already been made. I've also added the library to the project, how to recognize the images, and the folder structure of the project.
-
Hi,
Where do you put your shared library ?
Where do you put your application executable ? -
@SGaist said in How can I integrate an existing Qt project in another Qt project:
Where do you put your shared library ?
I have created the new static shared libary "mysharedlib" in the subdir "Test". Then I have added the libary to subdir "Test". I thought so with "add libary" I would have put my shared libary (look at third picture).
My application executable is in the folder "DataSaveModell" (look at third picture).
SUBDIRS += \ DataSaveModel \ mysharedlib
-
Or did you mean with "your application exectuable" the .pro-file of the feature "push notifications". This content is in the file "mysharedlib.pro".
-
A static shared library ?
You must also ensure that you build your sub projects in the correct order.
-
@SGaist said in How can I integrate an existing Qt project in another Qt project:
A static shared library ?
c ++ library - statically linked library
Where is my correct ordner??
I have send you very many pictures of my project. Can you tell me something useful and no fragments which I can not do anything or think about what you mean by that, please? -
@Robin-Hood said in How can I integrate an existing Qt project in another Qt project:
@SGaist said in How can I integrate an existing Qt project in another Qt project:
Where is my correct ordner??
Usually the library has to be build before the program
I have send you very many pictures of my project. Can you tell me something useful and no fragments which I can not do anything or think about what you mean by that, please?
Other way round. You gave us lots of fragments. Can't you upload the whole project somewhere?
Regards
-
ok yes, I upload my whole project here.
-
@Robin-Hood where?
-
I will now upload a different project than it was in the previous pictures. However, this is based on the same problem and is built exactly the same way. My problem is that my executable file (the project, which I want to include the library. It is located in the folder "QtAndroidJava2Cpp ") does not know the contents of my added library (here: "mylib ") and therefore does not execute. Once you have downloaded the zip file, you will see that I want to output several strings on the console (in Qt-Creator), which are located in "App/mylib/mylib.cpp " and "App/mylib/mylib.h ."
Here you can upload this project under:
zippyshare -
Some words in advance, before I even try to compile the project.
TEMPLATE = subdirs
SUBDIRS +=
QtAndroidJava2Cpp
mylib
CONFIG += orderedNever use CONFIG+=ORDERED. (And if, you would have to specify the lib first, because the app links against the lib). The correct way is to specify dependencies:
QtAndroidJava2Cpp.depends = mylib
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/mylib/ -lmylib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/mylib/ -lmylibd
else:unix: LIBS += -L$$OUT_PWD/mylib/ -lmylibINCLUDEPATH += $$PWD/mylib
DEPENDPATH += $$PWD/mylibwin32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/mylib/libmylib.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/mylib/libmylibd.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/mylib/mylib.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/mylib/mylibd.lib
else:unix: PRE_TARGETDEPS += $$OUT_PWD/mylib/libmylib.aAll this does not make sense in the pro-file that contains
TEMPLATE=SUBDIRS
. If you need global configurations, put them in aglobal.pri
and include them in the pro files that needs them.So far.
Edit:
One more hint: Don't include the .pro.user files when you upload projects. They cannot be shared and just bloat the archive.
That said, I tried to compile your project but it doesn't work as I don't have
androidextras
(and not even an android compiler).But I also wonder, why you copied mysharedlib_global.h into the QtAndroidJava2Cpp project? It should be in the shared library project.
Regards
-
Please find a small subdirs example here: https://www64.zippyshare.com/v/XQKzMN1b/file.html
It does what you request, and you should get the point.
Regards
-
Thank you first. I am still very inexperienced in terms of programming with Qt. :/
I have now downloaded the project from you "SubdirsExample". Unfortunately, I can not do it correctly. I get the error messages:c:/users/robin/android-ndk-r17b/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot find -lLib ..\..\SubdirsExample\App/mainwindow.cpp:13: error: undefined reference to 'Lib::greet()' collect2.exe: error: ld returned 1 exit status make[1]: *** [libApp.so] Error 1 make: *** [sub-App-make_first] Error 2 make[1]: Leaving directory `C:/Users/Robin/Documents/build-SubdirsExample-Android_f_r_armeabi_v7a_GCC_4_9_Qt_5_11_1_for_Android_armv7-Debug/App' 09:44:22: Der Prozess "C:\Users\Robin\android-ndk-r17b\prebuilt\windows-x86_64\bin\make.exe" wurde mit dem Rückgabewert 2 beendet. Fehler beim Erstellen/Deployment des Projekts SubdirsExample (Kit: Android für armeabi-v7a (GCC 4.9, Qt 5.11.1 for Android armv7)) Bei der Ausführung von Schritt "Make"
I have testet with different devices (with a Android device and with Desktop Qt 5.11.1 32 Bit). Additional I have tried the programm under Windwos and Linux, but the same error message.
I think that the error is in the blue marked line. The compiler tried to read the Lib.lib File, but in order "Lib" I have only:
lib.cpp
lib.h
Lib.pro
lib_global.hI don´t have a .lib-File.
This is your program. Do you have the same error or do you know, where is the problem in detail?