A few design questions...
-
Of course. You can simply use you QML scene as a single widget in your app rather than the entire application GUI. Just add a QDeclarativeView to your form and set it to use the specified QML file:
@
QDeclarativeView *view = new QDeclarativeView;
view->setSource(QUrl::fromLocalFile("myqmlfile.qml"));
view->show();
@ -
Basically it is similar to what we already did in the other thread. The main difference is that instead of simply emitting a signal for your calculated values we declare those values as properties of the QObject (using the Q_PROPERTY() macro) and add a signal that is used to notify interested parties (the QML items) about changes to those property values.
When the QML runtime gets those signals it updates the relevent items in your QML scene that have properties bound to your C++ object's properties in some way.
It's not as hard as it sounds ;-)
-
OK, I'll start on that in a bit. A couple of questions:
- does using QML mean that I'm no longer using my widget.ui file, or do they work together?
- regarding QML: I think I may have mentioned that later this year I'll need to design a genuine GUI (for products based on the ASIC that I'm currently simulating). Is QML appropriate for applications like that as well? I ask now, because I'd like to choose one method of implementation and stick with it for both the simulator and the product GUI.
Thanks!
-
1: depends on your design. If you use a QML file for your whole UI, yes. Otherwise, the QML view is just a part of your UI design, and one that would be part of the actual .ui file.
2: to decide that, you need to tell us about the criteria, and even then it is hard for us to advise you on that. QML may be a candidate, but...
-
Thanks, Andre. Tell you what: I'll spend today playing with QML and doing some reading.
Regarding the upcoming product GUI: think of how you configure a home DSL modem, except we (probably) won't be using a browser to reach the embedded application.
I'll be back later with (I'm sure) some questions.
-
QML or a QWidget based GUI will work fine for that. Depends how much you want in the way of animations or how much you would like it to look native on your target platform. Having said that QML can be made to look native and we may see some native looking QML components coming out in the course of the coming year.
-
Not directly related to the thread, but I've stumbled across an issue that I've been wondering about.
I'm running on a Mac platform. The code that Zap posted above won't work unless I move my QML file into the resource for the binary. I don't like to do this, because 1) it's a minor hassle, and 2) it seems like a maintenance issue that I don't need.
Does Qt have any hooks for setting a default directory, or putting a prefix on files to direct them to somewhere else? I'm trying to avoid any hard-coding here, though some may be necessary.
I did find this thread:
"thread on setSource":http://developer.qt.nokia.com/forums/viewthread/656Which seems related, but not quite the answer.
Any advice on how to handle this?
-
Decisions, decisions. An absolute pathname, and I bet it won't port to other platforms. Relative pathnames seem weird here, too.
I don't suppose Qt supplies a pathname for the project, does it? I can't see how it could, but that would solve the problem.
-
What you can do is ionstall the file besides you exe and use QCoreApplication::applicationDirPath()
True, but then the QML file is out of the source structure. I'm trying to preserve a separation between source files (of all kinds) and makefile output. It seems like good CM practice if nothing else. I guess I'm probably stuck with the relative pathnames, huh?
-
but the *.pro files are described in the qmake "documentation":http://doc.qt.nokia.com/latest/qmake-manual.html
"lmgtfy":http://www.lmgtfy.com/?q=qmake+adding+copy
e.g. "this page":http://paulf.free.fr/undocumented_qmake.html
or this on "stackoverflow":http://stackoverflow.com/questions/3984104/qmake-how-to-copy-a-file-to-the-output
-
You can do this by defining a custom target in your .pro file. Something like this will do it:
@
myresources.path = $$(MY_INSTALL_ROOT)/resources
myresources.files = myqmlfile.qmlINSTALLS += target myresources
@The above depends upon the environment variable $MY_INSTALL_ROOT being set. However, this hardcodes the install path.
Instead, it is better to get rid of the $$(MY_INSTALL_ROOT) part of the path and use the DESTDIR feature of make to specify your installation root:
@make DESTDIR=/my/installation/path install@
That separates the install path from your project files.
-
Sorry if I seem a little slow on the uptake here -- I'm coping with multiple unfamiliar concepts. It's been over 20 years since I've used makefiles, and I'm still trying to figure out project files, qmake, QDir and other stuff.
Zap: I like the way your approach looks. I can't find anything on DESTDIR in the docs, though. It's not clear to me how this approach obviates the hardcoding issue; it seems to just postpone it. Obviously I'm not understanding the whole thing.
Thanks.
-
First: Go with the Resource directory in the application bundle. That's the expected path on OS X. One should not change those things only when it is absolutely necessary.
qmake has support for adding additional files to the bundle:
@
APP_QML_FILES.files = path/to/file1.qml path/to/file2.qml
APP_QML_FILES.path = Contents/Resources
QMAKE_BUNDLE_DATA += APP_QML_FILES
@This installes the files to YourFancyApplication.app/Contents/Resources - just where it belongs on OS X :)
EDIT: Some more background links in the new "wiki article":http://developer.qt.nokia.com/wiki/Resource_files_in_OS_X_bundle