跳到內容

QML and Qt Quick

Looking for The Bling Thing(tm)? Post here!
20.1k 主題 77.7k 貼文
  • Pass data between qtquick controls (slider) and C++ application

    8
    0 評價
    8 貼文
    4k 瀏覽
    sajis997S
    Hello forum, I did not get much of a response from my last post. I believe that I did not explain the issue well enough. Let me try again. Consider the following class structures: [code] class A : public QObject { Q_OBJECT public: A(); ~A(); void initialize(); GLint method1(); private: GLint var1; } [/code] Lets describe a bit about the class A. The public method method1() returns the value for var1. The initialize() must be called prior calling method1() so that the member variale value contains the updated value. Now lets look into another class as follows: [code] class B : public QQuickItem { Q_OBJECT public: B(); Q_INVOKABLE float method2(); private: float var2; A* a; }; ................ ................ B::B() { a = new A(); } float B::method2() { return (float)(a->method1()); } [/code] While running the program I found that B::method2() is always returning ZERO, which is incorrect value. The method2 is called from the qml file as follows: [code] BItem { id: bItem } Slider { id: slider1 opacity: 1.0 minimumValue: 1.0 maximumValue: bItem.maxPatchVertices() stepSize: 1.0 Layout.fillWidth: true onValueChanged: bItem.outer = value } [/code] I tried the understand the program flow with the help of the debugger and found that B::method() is called and the value is not updated even after the A::initialize() changes the value. I have seen examples where C++ class member variable is updated from the qml , not vice versa. I believe I am experiencing the latter issue here. As you can see from the qml file, I trying to get the updated value from C++ class member function and set it as a property value fom the slider. Any idea/refference/example to resolve this ? Thanks
  • C++ QML Wrappers wise or not

    4
    0 評價
    4 貼文
    2k 瀏覽
    J
    If you write a signal in your Network c++ class and emit it doesn't solve your problem? @ class Network : public QObject { public: Q_OBJECT public: Network(QObject *parent = 0); ~Network(); signals: void message(message); };@ so, in qml: @import myapi Network { id: myNetwork onMessage: {console.log(message)} }@
  • More boxes to move in the same line.

    7
    0 評價
    7 貼文
    1k 瀏覽
    p3c0P
    well then if it is at the same time then I think that your earlier approach is correct. For that you can create a separate Component or a QML file which will contain the PathAnimation and the Box and then later call this Component/QML file as many times you need.
  • [SOLVED] Reference error: id is not defined

    3
    0 評價
    3 貼文
    16k 瀏覽
    P
    Thank you very much! Now it works.
  • How to iterate for each element of collection

    2
    0 評價
    2 貼文
    800 瀏覽
    D
    Hi I would probably do something like @ GridView{ id: myGridView anchors.fill: myBoard model: boardModel cellHeight: myBoard.frameSize cellWidth: myBoard.frameSize property int which : -1 //new delegate: SingleTile{ id : theDelegate Connections{ //new target : myGridView onWhichChanged :{ theDelegate.setFlipped(myGridView.which); } } } } function flipFrames(which){ myGridView.which = which; } @ The idea (which I find useful with QML) is to use property bindings and let each element act individually. This is a bit different from c++ where we are used to looping over a collection and tell each element what to do.
  • Flickering FBO When Resizing Vertically

    1
    0 評價
    1 貼文
    973 瀏覽
    尚無回覆
  • Rearranging Items contained in GridLayout?

    4
    0 評價
    4 貼文
    1k 瀏覽
    p3c0P
    Ok. Take your time and Happy Coding! :)
  • Qt Quick designer: how to add or bind property alias?

    3
    0 評價
    3 貼文
    1k 瀏覽
    W
    Thanks Thomas, then I can't use it in the community edition. :-(
  • How can I send a signal to an Item which is inside a Loader ?

    2
    0 評價
    2 貼文
    1k 瀏覽
    p3c0P
    Hi, AFAIK, you can do it in following ways: Using "Connect()":http://doc.qt.io/qt-5/qtqml-syntax-signals.html#connecting-signals-to-methods-and-signals Using "Connections()":http://doc.qt.io/qt-5/qml-qtqml-connections.html An example : @ Item { id: item width: 100 height: 150 signal sendMessage(string msg) Loader { id: loader width: 100 height: 100 sourceComponent: comp Component.onCompleted: item.sendMessage.connect(loader.item.setText) //comment Component.onCompleted if using Connections and vice versa } // Connections { // target: item // onSendMessage: { // loader.item.setText(msg) // } // } Component { id: comp Rectangle { anchors.fill: parent color: "red" function setText(msg) { mytext.text = msg } Text { id: mytext anchors.centerIn: parent } } } Button { text: "Click Me" y: 110 onClicked: item.sendMessage("Hello Qt") } } @
  • Exposing C++ model property of type QList<QObject*> to QML

    20
    0 評價
    20 貼文
    22k 瀏覽
    J
    I know this is an old thread, but I had a similar problem to that of the original poster (stas2) I was able to have the QML read the QList properties correctly after using the following syntax in the QML view: @ListView { model: appData.axes delegate: Text { text: model.modelData.name } }@
  • Changing button image loses pressed signal

    8
    0 評價
    8 貼文
    6k 瀏覽
    JKSHJ
    First, it's helpful to understand the following: The QML language is designed by Qt engineers, specifically for Qt applications. However, the JavaScript language is designed by people that are completely unrelated to the Qt Project. JavaScript is far older than QML, and it is widely used outside of QML. JavaScript is an imperative language. QML is a hybrid language. It consists of imperative parts (which are JavaScript expressions) and declarative parts. In other words, QML contains JavaScript plus other things. If you don't know the difference between declarative and imperative programming, do some "extra reading":http://stackoverflow.com/questions/1784664/what-is-the-difference-between-declarative-and-imperative-programming Secondly, make sure you understand how a "JavaScript conditional operator":https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator works. Ok, now to address your questions and observations. To specify a property and a signal handler in a QML component, you need the following format: @ <COMPONENT> { <PROPERTY>: <JAVASCRIPT_EXPRESSION> <SIGNAL_HANDLER>: <JAVASCRIPT_STATEMENT> } @ Examine the snippet above: The colon "assigns" JavaScript code to a QML component's attribute. Note that a property's JS code is used differently from a signal handler's JS code: The JAVASCRIPT_EXPRESSION associated with a PROPERTY is evaluated every time a variable in the JAVASCRIPT_EXPRESSION changes value. The JAVASCRIPT_STATEMENT associated with a SIGNAL_HANDLER is evaluated every time the corresponding signal is emitted. [quote author="Binary91" date="1419677212"]when I use this line outside of the js statement using the colon ":", the binding works perfectly: @{ image.source: mousearea.pressed ? "imgPressed.png" : "img.png" mousearea.onClicked: { } }@ [/quote] The QML attribute is image.source (a property) Your JavaScript expression is mousearea.pressed ? "imgPressed.png" : "img.png" [quote author="Binary91" date="1419677212"]I don't understand why the following line in a js statement is a static assignment and not a property binding: @Button { mousearea.onClicked: { image.source = mousearea.pressed ? "imgPressed.png" : "img.png" } }@ [/quote] The QML attribute is mousearea.onclicked (a signal handler) Your JavaScript statement is image.source = mousearea.pressed ? "imgPressed.png" : "img.png" Remember, this statement is evaluated whenever the clicked signal is emitted. ** Every time you release the mouse button, the QML engine checks the value of mousearea.pressed, and then chooses a URL, and then assigns that URL to image.source ** mousearea.pressed is always false when you release the mouse button, so the same URL is chosen every time this statement is evaluated. That's why it feels like nothing is happening. [quote author="Binary91" date="1419677212"]when I try to use the colon ":" in the js statement like this: @{ mousearea.onClicked: { image.source: mousearea.pressed ? "imgPressed.png" : "img.png" } }@ , then QtCreator throws an error and doesn't compile my code...[/quote] The QML attribute is mousearea.onclicked (a signal handler) You attempted to use image.source: mousearea.pressed ? "imgPressed.png" : "img.png" as the JavaScript statement. However, this is illegal JavaScript code. Remember, QML needs to follow the rules of JavaScript Is this understandable? If not, please let me know and I'll try to explain differently.
  • [SOLVED] QtQuick 2 offscreen rendering - no Camera issue

    1
    0 評價
    1 貼文
    617 瀏覽
    尚無回覆
  • How can I create simple container directly usable in QML designer.

    2
    0 評價
    2 貼文
    833 瀏覽
    T
    Here you can find a small example how to integrate a custom qml plugin into the designer: https://qt.gitorious.org/qt-creator/qt-creator/source/394c9dd5507df610f7d60a56b7bf7e707a59142f:tests/manual/qml/testprojects/plugins This is a manual test case, that we use to test the integration of custom QML items. If you put the QML file next to the file you edit (no import needed) nothing is required to get a basic integration. To get something like a collapsable GroupBox working I would suggest to overload the default property using an lias property, like the GroupBox of the Qt Quick Controls does it. The state of of the GroupBox should be exposed as a boolean property.
  • How to find / use Qt Quick 2D Renderer in Qt 5.4?

    9
    0 評價
    9 貼文
    3k 瀏覽
    SGaistS
    You're welcome ! Since you have everything now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)
  • [Solved] Qt Quick QML Image Quality

    5
    0 評價
    5 貼文
    2k 瀏覽
    M
    I've found a solution and it works very well. Seems like it's a depth issue. Add this before your view show object. @ // CORRECTION DEPTH QSurfaceFormat surfaceFormat; surfaceFormat.setAlphaBufferSize(8); v.setClearBeforeRendering(true); v.setColor(QColor(Qt::transparent)); v.setFlags(Qt::FramelessWindowHint); v.setFormat(surfaceFormat); // CORRECTION DEPTH END@
  • Is is safe to upgrade to Yosemite OS X regarding Qt Creator ?

    6
    0 評價
    6 貼文
    2k 瀏覽
    T
    I still have a lot of work to do on on my project in Windows so I have only compiled the debug version in OSX. It works fine. The only issue so far is I need to adjust the application font size. Some of the words are cut off because the font is too large. I still have to learn more about creating a release version in OSX. I haven't found any articles about a successful static deployment in OSX so I think I'll have to bundle all of the needed DLLs.
  • [SOLVED] First steps with ListView

    12
    0 評價
    12 貼文
    3k 瀏覽
    B
    [quote]verticalCenter / horizontalCenter will position it to the center provided size is specified. The problem is that you cant use top, bottom, and verticalCenter anchors at the same time OR left, right, and horizontalCenter anchors at the same time. AFAIK verticalCenter and horizontalCenter will be ignored in that case.[/quote] Well, that makes sense, because using anchor top & anchor bottom already does the effect of anchor top + verticalCenter I think... Ok, so everything is clear. Thank you really much! Cheers,
  • Set root index in PathView

    2
    0 評價
    2 貼文
    792 瀏覽
    A
    Answer to my question is "QML DelegateModel":http://doc.qt.io/qt-5/qml-qtqml-models-delegatemodel.html
  • Scrollbar for list view

    3
    0 評價
    3 貼文
    2k 瀏覽
    D
    Put the ListView in a "ScrollView":http://doc.qt.io/qt-5/qml-qtquick-controls-scrollview.html
  • Cannot assign to non-existent property in another qml file

    5
    0 評價
    5 貼文
    11k 瀏覽
    D
    You have probably already noticed that the id in marqueeText.qml should not start with an upper case letter as described "here":http://doc.qt.io/qt-5/qtqml-syntax-objectattributes.html#the-id-attribute I main.qml you do @ MarqueeText { id:scrolltext width: 800 height: 48 text: "Qt Quick Digital Signage Demo" } @ This allocates a new instance of the MarqueeText class/element and has nothing to do with the id you provided in the MarqueeText.qml file