[Qt-qml] Starting an external program from QML?

Raymond de Vries reedev at xs4all.nl
Mon Oct 25 11:43:16 CEST 2010


On 10/25/2010 9:59 AM, Kai Koehne wrote:
> On 10/25/2010 9:40 AM, ext Raymond de Vries wrote:
>> Hi,
>>
>> On 10/25/2010 8:30 AM, Kai Koehne wrote:
>>> On 10/25/2010 8:07 AM, ext Raymond de Vries wrote:
>>>> Hi,
>>>>
>>>> That makes sense indeed, stupid of me. Could you point me at an example
>>>> how to use the C++ slot from QML? I have been looking for this but I
>>>> guess I am missing something...
>>> There are actually multiple ways. One is to expose your slot to the QML
>>> context, see
>>>
>>> http://doc.trolltech.com/4.7-snapshot/qtbinding.html#calling-c-methods-from-qml
>>> .
>> Ah, I understand. I had seen that page before but did not realize the
>> use with standard widgets.
>>> (The example shows you how to register a named object in the QML
>>> context. If you don't like the objectName.slot() notation, you should
>>> have a look at QDeclarativeContext::setContextObject(...)).
>>>
>>> Another way (and IMO better style) is to declare a signal in the QML
>>> root element, and then connect it to the slot in the C++ part, e.g.
>>> something like:
>>>
>>> x.qml:
>>>
>>> import QtQuick 1.0
>>> Rectangle {
>>>       signal startAppRequested
>>>       // ...
>>> }
>>>
>>> x.cpp:
>>>
>>> QDeclarativeView view;
>>> // ...
>>> view.show();
>>> connect(view.rootObject(), SIGNAL(startAppRequested()), this,
>>> SLOT(runApp());
>> This looks good indeed, and it makes conversion from C++ UI to QML UI
>> much easier. This helps a lot!
>>
>> Btw a little OT for here maybe but to be sure: I need to build Qt myself
>> from git in order to use QtQuick like in your x.qml, right?
> Right. The QtQuick 1.0 namespace will be introduced in 4.7.1 :
>
> http://www.mail-archive.com/qt-qml@trolltech.com/msg01040.html
>
> Just keep "import Qt 4.7" if you develop with 4.7.0.
No problem. Already building qt git master... Thanks for the confirmation.

Regards
Raymond


> Regards
>
> Kai




More information about the Qt-qml mailing list