Qt Creator: Projects that use other projects as libraries - qt-creator

I've written a small library as a Qt project using Qt Creator, now I want to create a small GUI application that can be used to test it as part of the development process, so it could be like this:
Project root at:
~/code/mylib
Library project and associated code:
~/code/mylib/corelib/corelib.pro
GUI test tool and associated code:
~/code/mylib/libgui/guitool.pro
So far I've only been able to make things work by setting up LIBS+= in the GUI project's .pro file, manually building the library, copying the library's .a file to the GUI directory, and rebuilding the GUI project. A tedious process. Worse: I'm developing the project now on Linux but need to make it build on Linux and Windows, and this manual build style will probably make that harder.
I suppose there's a way to do make Qt Creator aware of the relationships between the projects, so for example building the GUI tool in debug mode use the debug version of the library, or making changes to the corelib would necessitate a build in the GUI, building on some OS would use the libraries OS-configuration...etc
This kind of thing is a couple of clicks away in Eclipse and Visual Studio, but I can't seem to get it working in QtCreator. I've tried "Add library->Internal library" and creating a 'subdirs' project but neither seems to work. I feel it's probably a simple step that I'm missing somewhere, any help?

Try again to use subdirs feature. It have own wizard "Project with subdirectories", but in your case it's easier to write it manually (in example I've added "ordered" to ensure that order of compilation is always correct).
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = corelib guitool
Than you can add libary to your GUI application with wizard (accessible from context menu inside .pro).

Related

QML module not found error

When using QtCreator, I display a qml file in the editor. The qml file is for a file named main.qml that is a plugin.
I then click on the Design button. It displays the error message: QML module not found.
If I take the Go to error link it goes to a line containing the following import com.name.os.app.all 1.0. This is the location of various component qml files needed by the plugin.
I have added the path c:\users\me\ui\viewer\ to my QML_IMPORT_PATH env variable. If QtCreater appends the com.name... from the qml file import statement to the pathname I added to QML_IMPORT_PATH, it would find the desired directory. It doesn't.
The project uses qmake.
I have tried using qmlplugindump.exe to generate a qmltypes file for my main qml view container file, but qmlplugindump.exe gives me an error saying the component is not ready and file::///c:/Users/name/ui/viewer/modules/app/qml/com/name/os/app/all/typelist.qml:2:1 module MyViewContainer.qml is not installed.
The command I used was qmlplugindump.exe MyViewContainer.qml 1.0 c:\users\myname\ui\viewer\modules\app\qml\com\name\os\app\all\ > ...
This Error Ruined My Life
Real Solution for "QML module not found error":
lets say if you have plugins in directory like this, with qmldir inside it
"myproject/modules/mymodule/blabla.qmldir"
you need to import parent directory like this in ".pro" file :
QML_IMPORT_PATH += $$PWD/modules
not like this (this one wont work):
QML_IMPORT_PATH += $$PWD/modules/mymodule
//---------------------------------------------
side note:
this is going to happen in other part of qml too like qmlplugindump you need to give parent directory not exact folder!
but windeployqt is working with exact folder
for example:
qmlplugindump lib 1.0 C:\Users\Administrator\Documents\projectName\3rdparty > C:\Users\Administrator\Documents\projectName\3rdparty\lib\lib.qmltypes
//---------------------------------------------
and second most important part is QML emulation layer
in Qt Creator go to tools->option->Qt Quick->Qt Quick Designer
select "Use Qml emulation layer that is built with the selected qt"
if its already selected look at textbox under that "Top level build path"
it should refer to Qt version bin directory which should be same as plugins Qt version :
..\5.12.1\msvc2017\bin
for me its :(it should be same version as you used for kits and blabla)
C:\QtN\5.12.1\msvc2017\bin
it should not be like this one :
C:\Users\Administrator\AppData\Roaming\QtProject\qtcreator\qmlpuppet
dont forget to deploy after adding new item in plugins(cmd command) :
windeployqt --qmldir C:\Users\Administrator\Documents\projectName C:\Users\Administrator\Documents\build-projectName-5_12-Debug\debug
and plugin dump :
qmlplugindump lib 1.0 C:\Users\Administrator\Documents\projectName\3rdparty > C:\Users\Administrator\Documents\projectName\3rdparty\lib\lib.qmltypes
after this point if QtCreator gives error for new Objects in Plugins you need to restart QtCreator thats it!
if still there is problems you need to - Clean All - Run Qmake - Rebuild all which solves so many issues.
and in some cases you need to put your qml files into 5.13.1\msvc2017\qml or whatever is for your qt version
Have you tested this plugin fully? I ask this because I have written a number of plugins and have run into this issue multiple times.
Possible issues include the version of Qt you are using, and some form of naming error in the plugin uri / classname.
I have an app that I build for multiple versions of Qt and it seems that the qmlplugindump tool has different levels of effectiveness.
Sorry to be so general, but hopefully it points you in the right direction.
From within QtCreator, do a "project-clean", and then rebuild. The module will be found.
I had the same problem and stumbled onto your question. After some effort, the "clean" and rebuild worked.
There seems to be an "incomplete-dependency-checking" during the build process to "understand" that the main.cpp needed to be rebuilt, which would then expose the qmlRegisterType<MyType>() so that it can be found within the main.qml.
After two days of googling and headache, thanks to #MoreMag, I finally worked it out! I just write down some key points here, hoping to help you guys! 😀
Problem:
Solution:
â‘  go to Tools -> Options -> Qt Quick -> QML Emulation Layer.
â‘¡ check Use QML emulation layer that is built with the selected Qt
â‘¢ click Browse button choose the Qt building environment bin folder. The path is in the form of D:\Qt\5.15.2\msvc2019_64\bin. Here I'm using the msvc2019 64bit building environment.
â‘£ click Apply button and restart the Qt creater. Done!
Qt Creator document says
A QML emulation layer (also called QML Puppet) is used in the Design mode to render and preview images and to collect data. To be able to render custom types correctly from QML modules, the emulation layer must be built with the same Qt version as the QML modules.
By default, a fallback emulation layer is provided by Qt Creator and built with the same Qt version as Qt Creator. Therefore, your QML modules will mostly not work out of the box.
I guess this issue is caused by the fact that the default QML Emulation layer may not be compatible with some QML modules. In my case, it's QtMultimedia module.

How can i set what version of a product I'm in Eclipse?

I've created, debugged, and revised a project that I've been working on, but now I want to be able to specify what version of the binary I'm on. I'm using Eclispe-CDT with MinGW to make this project on my local system, so there is no versioning software involved. Does anyone know how to specify this for both Windows and Linux platforms?
On Windows, the idea is to produce a COFF file with the relevant information.
That is done by adding a step to the build, using windres (found also here).
See this thread as an example.
you could add windres via the project properties/Builders as an additional builder and add the generated object file in the C/C++ Build/GCC C++ Linker/Miscellaneous/Other Objects.
Then you
- a) could do a clean build if the resource is changed or
- b) could change the build options (if you have patience) to change to do a clean build every time you save the project.
On Unix, this doesn't seem to be supported in a similar fashion.

Using Xcode for generic C/C++ development

I'd like to use all the power of Xcode for generic C/C++ projects but I can't figure out what are the basic steps to configure a new Xcode project and attach it to an existing source tree of a legacy, plain, C/C++ project.
Creating a new empty project, attaching it to a source tree and configuring a build target (using GNU Make) was a really silly task.
I can't figure out how to enable source code indexing in order to enable source refactoring tools, searching and fast-jumping and all the amenities that makes the Xcode programmer's life great.
Moreover I'd like to use the internal debugging facilities…
Does anyone point me to a tutorial, a hint or whatever could be useful?
Thanx
I've found a (dirty) path to enable refactoring tools:
I've added a new standard «console target» to the project and added all the source files under the Build Phases > Compiled Sources.
Refactoring tools now works. Having two targets doesn't seem to be a relevant issue (elegance apart)
Personally, I wouldn't attempt to use legacy Makefiles, even though I think there's some support for that.
Typically what I do with a traditional C/C++ project is to store my XCode project folder at the root of the project. So it might look like:
--myApp
--src
--inc
--myApp Xcode
I then drag the src folder and inc folder into the project navigator. This gives me an Xcode project to compile with on the Mac, and then I have the traditional Makefile for compiling on Linux (actually, I prefer CMake for other platforms, but either way works).

Creating a library (.a) in Mac OS X and Xcode

I'm in the process of porting some code from Linux to Mac OS X. The code is a static library that you add to your code. Basically after you compile the code you get a MyLib.a that can be linked to whatever project you want.
I'm managing the "project" via a Makefile.
Is there a way to have a project on Xcode that ultimately produces the same kind of library? How?
Thank you for the help.
Sure. You don't say so, but I am assuming you are using C or C++ as source.
Assuming you are using Xcode 3.2.2, you can create a new project (File > New Project...), which will bring up a New Project window with available project templates. Select the "Framework & Library" category under Mac OSX from the list on the left. You should now see a "BSD C Library" and "STL C++ Library" among the other library and framework types. For building a static library like you described you want the "BSD C Library" option. There are static and dynamic options for this which you will see when you click on the icon, but static is default.
Depending on which version of Xcode you are using, the location of the project template may be a little different since Apple has been changing this UI for the New Project window fairly frequently. So if you are not using 3.2.2 you may need to poke around the available projects a little bit.
Oh, and don't worry if you are trying to build C++. Event though this says it is for C, C++ libs build just fine as well.

Adding QT Form to an existing VS2008 project

I have a normal VS2008 project that I've been working on for awhile that is doing some OpenGL based stuff. The main window is created with GLUT and until now that has been sufficient for my GUI.
Now, however, I want to add a small window of buttons, and I need to do it in a cross platform way, so I decided to use QT. I've installed all of the QT components including the VS add-in and everything seems to work fine, but I can't figure out how to add a QT form to my project (since it wasn't originally configured to use QT). I really don't want to create a new project in QT Creator and migrate all of my existing code into it, since I already have development environments set up and configured correctly for this code base on three different platforms. Is there some way to tell visual studio to just do the right thing with the .ui file so I can use it in my existing project?
EDIT: By the way, when I say I can't figure out how to add a QT form to the project, I am able to add a form--meaning a .ui file--that when clicked on opens the QT designer. What I can't figure out how to do is make it compile. It has a "custom build rule" added by default, but the command line is blank, and I don't know enough about qmake to get it to build the .ui file for me.
I use these line as custom build rule (where $QTDIR is the location of your Qt installation):
"$(QTDIR)\bin\uic.exe" -o ".\tmp\ui_$(InputName).h" "$(InputPath)"

Resources