Qt Creator and QML Live Preview - qt

The problem now is that I don't know how I can use qml live preview?
I saw a video:
https://vimeo.com/145921618
I saw this post about erase this function for Qt Creator.
How i can implementlive coding into my app?

Perhaps you mean Terrarium?
Terrarium is a cross platform QML Playground: the view renders lively
as you type in the editor, makes prototyping and experimenting with
QtQuick a lot more fun!
It monitors changes in its TextEdit, and triggers the view to reload
source from the local http server. If you're looking for a file system
watcher implementation, please refer to QML LiveReload.
Or LiveReload?

As is evident from the video, this is as simple as auto reloading a QML file each time a chance to the file has been saved.
You can easily do that yourself, set up a QFileSystemWatcher and every time the file is modified, load the file in a QML view. And there you have it.
Of course, this is only good for previewing standalone components which can work on their own. You could go further, set the file system watcher to monitor the entire QML project and reload the main QML file every time something changes. It is a two step process, you need to monitor the directory, which only reflects adding or removing of files, and you subsequently add or remove those files from watching for changes.

Just for the sake of it, I want to share another tool that I found online.
It is a web based QML editor that gives immediate preview while writing the code. It has its limits, but still it's pretty useful for live QML coding
https://qmlweb.github.io/

If someone is still interested, in my Qt 5.10 installation, there is a qmlscene.exe in bin folder (same location as qmake or assistant). Running on command line is fine, however it is not in Qt creator.
PS: I found this:
http://doc.qt.io/qt-5/qtquick-qmlscene.html

Related

How to import the QML-Book examples into QT Creator 3.4.0?

How can I import these code examples into QT Creator 3.4.0 ? I tried the available import options but they don't work.
I tried to create an empty QML project and add the rectangle.qml file to it. When I tried to run it, nothing showed up.
The book examples contain files .qmlproject - which seems to be a project descriptor. I wonder if it is somehow possible to import these .qmlproject files into QT Creator, click and run the examples.
I think this link might help in finding the solution : https://forum.qt.io/topic/27525/what-is-qmlproject-file/3 .
Usually I'd say that you should go to File > Open File or Project... and select the .qmlproject and you're done, but support for this type of project file was disabled by default. If you try to do this now (I believe the change is in Creator 3.4), you'll just get an error message about Creator not supporting the mime type of the file, or something. Unfortunately, this is not a very useful error message for a beginner, and it won't tell you how to fix the problem.
If you want to use .qmlproject files in newer versions of Creator, you have to navigate to Help > About Plugins... and enable the QmlProjectManager plugin (it's under the Qt Quick section) by checking the box.
So this is how you should normally open project files in Qt Creator. As for the window not showing up, that's also commonly encountered and can be fixed by making the root item in your scene a Window:
Unlike QQuickView, QQmlApplicationEngine does not automatically create a root window. If you are using visual items from Qt Quick, you will need to place them inside of a Window.
Qt Creator's new project wizard handles this for you when you create a new Qt Quick project, as you saw when you got the "Hello World" window to open in your video. It was when you loaded concepts/rectangle.qml which had a Rectangle as its root item, that it stopped showing up. That QML file was likely used in a project where a QQuickView was displaying it.

QGraphicsItem does not show

I wrote a simple application that displays QGraphicsPixmapItems in a QGraphicsScene. The application should be portable without installing Qt on the operating system. I managed to copy only the needed dll files to start the application. Everything works except the QGraphicsItems are not displayed at all, although they are in the scene (wrote a logfile that counts the items).
I figured out that the items are shown correctly, if I copy my "portable" exe file into Qt\Qt5.2.1\5.2.1\mingw48_32\bin folder.
The opposite does not work: If I copy all of the bin-folder to my portable application folder, it does not work. How can I use a QGraphicsItem in a portable Qt application?
you might miss a plugin for the images you want to display.
make sure your application directory looks like this:
<root>
- <executable>
- <imageformats>
- <used image libraries>
I found the reason: I needed to add the folder Qt\Qt5.2.1\5.2.1\mingw48_32\plugins\imageformats to my "portable-app"-folder. In particular, the needed dll was qjpeg.dll.

QtCreator Designer signal/slot connections inconsistent with generated code

I'm working on a Qt project in QtCreator. The project has a dialog box with several UI elements, some of which have to be enabled/disabled according to what the user does. (i.e. If the user selects a radio button, then the form field has to be enabled.)
When I add a new signal/slot connection or delete an existing through the Qt Designer tool, the change shows up just fine in the preview. When I compile the application, though, the window still behaves exactly as it did before.
I investigated this by checking out the ui_WindowName.h file that the Qt Designer creates. Near the end of the setupUi function is a set of connect() calls. These connect() calls are consistent with the slot and signals that existed earlier today, but they do not reflect the changes I have made through Qt Designer since.
If I manually change the ui_WindowName.h file, then the UI works. But, of course, my changes get overridden if I ever try to chance anything from Qt Designer.
Even when I quit QtCreator and open it again, the Designer still shows the changed slot/signal connections while the auto-generated code does not reflect the changes.
Am I doing something wrong? Is there some way to delete whatever cache the Designer is storing or something to get things back in sync?
Thanks!
(One other thing: I'm using the stand-alone Qt Creator, not trying to develop in Visual Studio. The only other similar problem I could find on the web was from someone developing in Visual Studio, which doesn't support the automated signal/slot stuff.)
As usual, the answer is obvious once you realize it.
I moved the project in the course of working on it. There's a .pro.user file that keeps track of where the project is located. Without realizing that, I moved it along with the rest of the files.
As a result, I was editing one copy of the project and running the other.
The moral of the story: If you move a Qt project, remember to update your .pro.user file.
(Or you can just delete it. Qt Creator will prompt you to re-create it when you open the project.)

Starting an external application from QML

Is it possible to run an external application ( a .exe file ) from a QML file? I know that I can use Qt+QML and QProcess class but suppose that I only can access the QML file and can't recompile the c++/Qt part( Actually this project is a QML+Qt project)
If you can't access your C++ code, I'm afraid you can't.
There is an old open issue (2010) about this, but it seems it hasn't been considered a lot.
Anyway, it would be really easy if you could add something like this simple plugin to your project (but this would require rebuilding it).

QPixmap image loading problem

Basically I am trying to load the image as a texture using QPixmap:
texture[T_WALL] = bindTexture(QPixmap(":/images/wall.png"), GL_TEXTURE_2D);
The code works on my development machine, but not in the vm / other pcs without QT. Initially I was using jpegs and just assumed that I messed up the plugins, but as I understand, no plugins are needed for png files so I have no idea where the problem is.
Results are the same when loading local files and using Qt resources.
I am deploying libgcc_s_dw2-1.ddl, mingwm10.dll, QtCore4.dll, QtGui4.dll, QtOpenGL4.dll. Do I need anything else?
Try adding an imageformats directory to your application directory and put qmng4.dll there. See my answer to the question Qt dll deployment on windows
If it still does not work, get the Sysinternals suite which contains dgbview.exe that allows you to watch qDebug messages (even for release builds).

Resources