Can someone comment on the fact that for QML, any imperative JavaScript code is not executed unless it is part of an extra component. I am facing such kind of problem when I include the following code to my QML:
function qmlSlot(text){
page.data=text
if(page.data==="received")
page.color="black";
}
As the Qt Designer get frozen and shows the following warning:
Imperative code is not supported in the Qt Quick Designer
I read that building qmlpuppet installs an executable for rendering components in the /bin directory of the Qt building it. Qt Quick Designer checks for the Qt of the current project if a qmlpuppet is in the /bin directory. If yes it takes the qmlpuppet provided by the Qt version instead of the one provided by Qt Creator itself. In my case I haven't used the Qt static binary install, but instead built Qt from the source, thus qmlpuppet executable was generated and is already located at:
/usr/local/Qt-5.2.1/qtcreator/bin
-rwxr-xr-x 1 qml2puppet
-rwxr-xr-x 1 qmlpuppet
So, the executable qmlpuppet is placed where is expected to be found and still this annoying message continues.
The workaround I took at moment is to comment out any so called "Imperative code" for when I want to edit the front-end QML using Qt Designer. Then after take out those comments to have the "Imperative code" activated again. But this is very annoying, although the code compile and works as I expected it to behave.
So, should I get worried about this warning? Anyway, there is some mean to get rid of this problem, as it froze the Qt Designer?
This is currently a reported QtCreator Bug :
https://bugreports.qt-project.org/browse/QTCREATORBUG-10940?page=com.atlassian.streams.streams-jira-plugin:activity-stream-issue-tab
https://bugreports.qt.io/browse/QTCREATORBUG-10940
So don't be worried about the warning, it will be fix
Related
I just installed Qt creator (for the 10th time probably), and even when I follow the simple steps to create a new Qt Widget or Qt Console applications, I get this error. Extremely frustrated with various Qt Creator bugs. Help will be appreciate.
If you look closely at your workspace, you can see, that there are two projects. One project is called Sample, one project is called Widget. The active project is "Sample". You can tell that from the project browser as the Sample project is in bold letters. So building and debugging applies only to the Sample project.
The open file where you set your breakpoints in is "Widget/main.cpp", it belongs to the other non-active "Widget" project. So when you start the debugger, the environment warns you that this will not work. Completely correct behaviour.
Maybe try the following:
1- Ensure case sensitive typing of the file name and type the full path not just the name.
2- Delete configuration files that are automatically created.
3- Make sure the QT environment is setup correctly pointing to the required compilers, packages and resources.
4- Check if there are any missing environment variables on your machine.
The problem could be in the .pro
Check that you have the file into the source in the .pro
I am on MacOS 10.13.3, using Xcode 9 as my IDE, and trying to include Qt 5.10 in my Xcode project. I have installed Qt (with docs and examples) with Homebrew and ran many of them in QtCreator. Everything worked well up to this point.
My Xcode project is an extensive, complex project, the development of which has been active for a few years now, so switching to QtCreator or changing the structure of my project is not an option. I really need to add Qt to my existing Xcode project, which IMHO should be quite a natural thing to do given that Qt is a software development framework. However I have not been able to accomplish that yet. The upside is that in the process I have been learning quite a bit about Qt and its ecosystem. I now know how to use qmake, how to set up and successfully compile a project in QtCreator and how to create an Xcode project from QtCreator using qmake. As I said, I have been running many Qt examples and read pretty much every piece of documentation, blog and SO post I could find about this subject. To my surprise I haven't found a direct solution to this problem anywhere on the net.
So far I have included in my Xcode environment QtCore.framework, QtWidgets.framework and QtGui.framework, configured Xcode with the right search paths (Qt finds its files and frameworks) and include the right Qt headers in the code. However upon building my target I get a series of meaningless compilation errors.
Basically - if my understanding is correct - I can't just import Qt's components and frameworks I need, and set the right paths in Xcode just like I would do with any other framework. Qt 'features' a preprocessing step using MOC and UIC that sets it apart from other tools. So I examined the output of qmake and there are two files that the building system produces - qt_makeqmake.mak and qt_preprocess.mak which I think are responsible for the code generation step. Basically this is what I don't know how to translate into my Xcode environment.
Please feel free to tell me if my approach is not correct.
I am open to any advice or suggestion.
I would really like to integrate Qt into my project as Qt is such a powerful and complete framework. I hope someone will be able to help.
Thank you.
1 / In addition to setting the right path to Qt libraries and header files, which is fromwhat you said already done, you need to invoke the moc (Meta-Object Compiler) on your own Qt class which includes the Q_OBJECT macro. (basically every class you have made that are using signal/slot system).
MOChttp://doc.qt.io/qt-5/moc.html
This step must be done BEFORE compiling the project, and the result (the cpp generated moc files) must be compiled AND linked.
Now I am not an expert in XCode and MacOS development but for sure you have a way to add a custom step in your build process for doing that
2/ For UIC files : follow approximatively what is explained here (answer of Preetam, not the one validated) to obtain a .cpp and an .h file that you must include in your project too.
Hope this answer will help and point you toward the rigth direction.
Here is a post explained more in detail what I explained :
https://fmilicchio.bitbucket.io/2013/01/xcode-and-qt4-and-qt5/?
I am designing a user interface in Qt, and for longevity reasons I'd like to not require the Qt Meta-Object Compiler be used in future builds. I know the MOC parses certain macros in standard C++ code and generates C++ code based on these.
What I'd like to know is: where is the documentation of this generated code? I'd like to write the generated code directly into my relevant classes. While this might be cumbersome to do now, it will make the UI more stable in the long term by avoiding any issues if Qt disappears and the MOC ceases to exist.
Thanks!
Edit 1:
I am designing a Qt based UI in Visual Studio (NOT Qt Creator), for a C++ application that is not based on the Qt framework. I want to be able to distribute code that can be built as pure C++ with Qt code linked from specific libraries that will be packaged in. I want to be able to build this code on systems that do not have Qt installed. Hence the desire to avoid MOC. I'm not trying to offend any Qt fans out there, Qt is great. However, I need something a little different on this project, so suggestions to "Just use MOC" are not at all helpful.
Edit 2: I'm man enough to admit when I'm wrong. After some more thought and research it's clearly not worth trying what I was planning on doing. I'll just have to save the MOC generated code and distribute it as well. Thanks everyone.
Putting moc output verbatim into your code makes your code less portable, not more, as the moc output format changes more often (currently version 67) than source-incompatible major versions of Qt (currently version 5).
It seems to be on the whole not worth it to try to circumvent the MOC, as everyone here has pointed out to me. My solution will be saving the MOC generated source files in source control and packaging them along with the main application code for distribution.
What software Qt/QML pieces are needed to compile in an app to be able to debug/profile QML?
My current app is build using cmake and runs on a embedded device. Furthermore, I'm starting to use Qt 4.8.3 (until now 4.7.0).
I would like to use these fancy/cool features (for an embedded developer):
http://doc.qt.digia.com/qtcreator/creator-qml-performance-monitor.html
I've searched trough qt-project looking for help, but I haven't got clear what are the steps needed when you want to debug/profile a remote app, with a customize build environment.
So, I would like to know if it is needed any of the following steps, and in positive case, what is in fact the needed code.
Qt libraries ./configure specific options.
QtCreator specific options to attach/launch to remote app.
Cmake includes and libraries needed in the final app executable .
Any help, link, etc is welcomed.
With Qt 4.8 this got pretty easy. All required libraries are now part of Qt itself and you don't have to build the debug library for your Qt version yourself.
I'm developing a Qt/QML desktop application also built with CMake. I had to complete the following steps to enable QML debugging:
Include the debugging enabler into my application's start-up code
#include <QtDeclarative/qdeclarativedebug.h>
/* [...] */
QDeclarativeDebuggingEnabler enabler;
Add QML_DISABLE_OPTIMIZER=1 to execution environment of my application
This can be done within Qt Creator in the execution tab of the projects page.
Tick the checkbox for QML debugging also found in the execution tab
This adds the required command line parameters for the communication between Qt Creator and the QML debugger component embedded in the application
If everything went fine the application greets you with the following output if started in debug mode:
Qml debugging is enabled. Only use this in a safe environment!
QDeclarativeDebugServer: Waiting for connection on port 3768...
QDeclarativeDebugServer: Connection established
After that I was able to set breakpoints and inspect variables. Also the profiler accessible via the analyze page just worked.
Your case is obviously a little bit more complicated as your developing an embedded application.
Qt creator has no support for deploying and executing CMake-based projects on embedded platforms. You will have to do that yourself. Don't forget to pass the required arguments to your application to configure the QML debugging:
$ your-app -qmljsdebugger=port:3768,block
To attach Qt Creator to a remotely running application for a profiling session use the corresponding "External" entries in the "Analyze" menu in the Qt Creator main menu. Where is a likewise option for debugging with "Connect to Debug-Server" under "Debug" > "Debug".
I'm using Qt 5, and it got even easier. Just this one step was required on my side to do QML profiling:
#include <QQmlDebuggingEnabler>
...
QQmlDebuggingEnabler enabler;
Checking the docs all given answers seem to be unnecessary. Further it hardcodes debug code in releases. I have no clue why QQmlDebuggingEnabler would be necessary, but if you check the code here and here, you will recognize, that the instatiation of QQmlDebuggingEnabler is not necessary. Just include QQmlDebuggingEnabler and set the QT_QML_DEBUG flag e.g. like this (CMake)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DQT_QML_DEBUG ")
However according to the docs QQmlDebuggingEnabler is not necessary.
Furtermore: profiling unoptimized code makes no sense.
For me setting QT_QML_DEBUG as flag and checking the checkbox for QML debugging is sufficient.
Here is a "cleaner" alternative to #sebasgo's answer, item 1.
If you are using Qt5 with QtQuick2, you only need to define QT_QML_DEBUG before including QtQuick in some file (it does not matter what file, as long as it is a part of the executable). For example, it is sufficient to start your main.cpp with lines:
#define QT_QML_DEBUG
#include <QtQuick>
It won't hurt if you instead use compiler's -DQT_QML_DEBUG flag (e.g. via qmake DEFINES or cmake add_definitions directives), possibly only in debug builds.
If you are stuck with legacy QtQuick1 (in either Qt5 or Qt4) use QT_DECLARATIVE_DEBUG macro instead, e.g.
#define QT_DECLARATIVE_DEBUG
#include <QtDeclarative>
For the curious, here is a relevant Qt source, short and self-explanatory:
QtQuick2
QtQuick1 in Qt5
QtQuick1 in Qt4.8
With Qt 5.1 the new function qInstallMessageHandler was added.
It will let you catch, and log, errors and warnings so you can deal with them as you like.
I am building an application with mixed UI technologies (mostly C++ with some QML components included).
Suppose I have a QML item which I want to show inside a QDeclarativeView using syntax like this:
view = new QDeclarativeView(QUrl::fromLocalFile("foobar.qml"));
I have added foobar.qml to my project in Qt Creator which automatically adds this line to the .pro file:
OTHER_FILES += \
foobar.qml
Now, you would expect including the file into the project to imply that it should be copied to the build folder, but it doesn't, and I get an error about missing foobar.qml in the build folder when I run the application. I'd hate to add custom build steps just to copy QML sources around, so is there some "de facto" way of doing this?
One obvious solution would be to include the QML source through Qt's resource system. This is hinted at on the doc page about deploying QML based applications.
EDIT: Here is the complete solution. I should learn to RTFM.
Do you use shadow builds? If so the application is build in a directory parallel to the source code. For testing you can change the working directory in Qt Creator (Projects in the left bar, then Execution of your build target).
Using resources seems fool-proof, but it requires a rebuild every time any of the resources are changed.