1 | th.ssid { width: 100%; } /* Not necessary, but I guess you may want this*/ |
Macros to Simplify Redundant Q_PROPERTY() Hell
When you need to expose C++ object for accessing in QML, you may have to write a lot of annoying and trivial Q_PROPERTY()
s, getters, setter slots, signals, and private member variables. They will makes your class a mess (any mostly are duplicated). For example, a QString myFoo
:
1 | class MyObjectExposedToQml : public QObject |
Though only one property here but has been nearly create a getter/setter/signal/variable hell. So make some macros to get rid of these shit:
QML Controls 1.x ComboBox.onWheel Event & Flickable
If you place a ComboBox
on a Flickable
, you may unhappily notice that ComboBox
steals your mouse wheel events on Flickable
.
I think an UI component like ComboBox
which accepts mouse wheel event is totally a stupid idea and a great anti-pattern of UI/UX (the value of ComboBox is quite easily to be accidently modified). However, the API of QtQuick Controls, no matter 1 or 2, are totally moron. They totally don’t provide any API to deal with a lot of shit. So you have to workaround it:
1 | // MyComboBox.qml |
Explanation
- When component is loaded and instantialized (
Component.onCompleted
), use awhile
loop find any parent component hasflick
attribute. If found, assign_flickableItem
property as it. - Place a
MouseArea
to “steal the wheels events back”, which invoke_flickableItem.flick()
whenonWheel
.
One-By-One Promise
Let’s define a function to simulate calling API via Promise
and setTimeout()
:
1 | var callAPI = (api, arg) => new Promise((resolve, reject)=>{ // <- callAPI() always return this promise |
Use like this:
1 | callAPI("AddUser", { username: "ib", password: "ib" }).then((x)=>{ |
Result
1 | API "AddUser" called successfully! ==> {"username":"ib","password":"ib"} |
Call Multiple APIs Simultaneously
When you have to call a lot of asynchronous APIs simultaneously, you may use Promise.all()
like this::