I'm trying to use Qt Quick Componen开发者_JAVA技巧ts for Desktop from http://labs.qt.nokia.com/2011/03/10/qml-components-for-desktop/
I can build and install it just fine into it's own folder, and view the qmls with qmlviewer, but how do I use these qml components from my other projects in Qt Creator?
For example, I'd like to be able to use Dial.qml from the Qt Quick Components for Desktop to make a Dial element in a qml file in my project.
I used the instructions from the answer for this question: Qt How to make and install plugins? and was able to successfully use the qt quick desktop components within qt creator qml files. Here are more detailed instructions that I made:
- Download the tar.gz from http://qt.gitorious.org/qt-components/desktop/trees/master
- Extract the components anywhere (e.g. C:\qt-components-desktop).
- Open command prompt.
- run vcvars32.bat from "your Visual Studio"\VC\bin\ directory ... (usually C:\Program Files\Microsoft Visual Studio 9.0\VC\bin) in command prompt. e.g. "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat" You should receive a message similar to: "Setting environment for using Microsoft Visual Studio 2008 x86 tools"
- Set command prompt to use Qt Creator's bin path ... (usually C:\Qt\qtcreator-2.1.0\bin). e.g. SET PATH=%PATH%;C:\Qt\qtcreator-2.1.0\bin
- Set command prompt to use Qt's bin path ... (usually C:\Qt\4.7.2\bin). e.g. SET PATH=%PATH%;C:\Qt\4.7.2\bin
- Navigate in command prompt to the folder where you extracted the qt desktop components.
- Run the following commands: qmake jom debug jom install
- Copy the "components" folder from where you extracted the qt desktop components.
- Place it in "your Qt directory"\imports\Qt\labs ... (usually C:\Qt\4.7.2\imports\Qt\labs)
- Open the qmldir file inside the components folder in any text editor and observe the version number on each line (e.g. 0.1)
- Place the following import statement in any qml file to use Qt desktop components: import Qt.labs.components #.# where #.# is your version number (e.g. 0.1)
- Download the tar.gz from http://qt.gitorious.org/qt-components/desktop/trees/master
- unpack
- launch vcvars32.bat, then go to qt-components-desktop\ folder
- go to qt-components-desktop\components\ folder (cd components), type "qmake && nmake install"
- go to qt-components-desktop\src\ folder, type "qmake && nmake install"
These are alternative steps using a windows system and mingw which comes with Qt. For this example, I installed the Qt SDK to C:\QtSDK
. For these instructions, I used Qt 4.8.1.
- Download the tar.gz from http://qt.gitorious.org/qt-components/desktop/trees/master
- Unpack the components
- Add Qt's Desktop mingw bin path and Qt's mingw bin path to the PATH system variable with one of the two options:
- Option 1: (persistent) Using the control panel. (http://www.computerhope.com/issues/ch000549.htm)
- Navigate to "Control Panel" -> "System" -> "Advanced system settings"
- Select the "Advanced" tab
- Press the "Environment Variables..." button, located below the third groupbox and above the OK/Cancel button
- Under the "System variables" groupbox, scroll through the list and find the "Path" variable
- Double click or select the "Path" variable and press "Edit..."
- Go to the right-most end of the "Variable value:" field by either clicking within the field and pressing END on your keyboard or scrolling to the end with your mouse.
- Add a semicolon
;
then the path to Qt's mingw bin directory, in this case it isC:\QtSDK\mingw\bin
- Add another semicolon to the end and then Qt's Desktop mingw bin directory located in the version of Qt you are using, in this case it is 4.8.1:
;C:\QtSDK\Desktop\Qt\4.8.1\mingw\bin
- In the end, the addition to the path variable should look like this:
;C:\QtSDK\mingw\bin;C:\QtSDK\Desktop\Qt\4.8.1\mingw\bin
. Note that these paths could also be added anywhere and whichever order within the path variable. - Press "OK" to all opened windows to close and save your changes.
- Option 2: (temporary) Using the SET command. This method only lasts within the command prompt window it was executed. If the command prompt window is closed, the SET commands must be re-entered.
- Add Qt's Desktop mingw bin directory with
SET PATH=%PATH%;C:\QtSDK\Desktop\Qt\4.8.1\mingw\bin
- Add Qt's mingw bin directory with
SET PATH=%PATH%;C:\QtSDK\mingw\bin
- Continue the steps below with this same command prompt window. The SET commands are only set for the specific command prompt window you executed them in.
- Add Qt's Desktop mingw bin directory with
- Option 1: (persistent) Using the control panel. (http://www.computerhope.com/issues/ch000549.htm)
- If option 1 was used, open a new command prompt and navigate to where the qt desktop components are extracted. If option 2 was used, use the same command prompt to navigate to the qt desktop components folder
- Run the following command:
qmake && mingw-make install
- This command will automatically copy the compiled component files to
C:\QtSDK\Desktop\Qt\4.8.1\mingw\imports\QtDesktop
so there is no need to manually move or create any folders. - Make a new Qt Desktop project, and select the mingw which matches the Qt version as the toolchain.
Attempt to compile and run the following code:
import QtQuick 1.1 import QtDesktop 0.1 Rectangle { width: 100 height: 100 Button { id: button text: "Push me" onClicked: button.text = "Pressed" } }
- Done
At the time of these instructions, the latest version of the QtDesktop components is 0.1. To check the version you installed, navigate to C:\QtSDK\Desktop\Qt\4.8.1\mingw\imports\QtDesktop
and open the file qmldir
with a text editor and notice the version number on each line.
精彩评论