qtquick2

C++ class exposed to QML error in fashion TypeError: Property '…' of object is not a function

馋奶兔 提交于 2019-12-12 12:12:45
问题 I've successfully exposed a C++ class to QML. It is registered and found in Qt Creator. It's purpose is to connect to a database, as shown in following code: #ifndef UESQLDATABASE_H #define UESQLDATABASE_H #include <QObject> #include <QtSql/QSqlDatabase> class UeSqlDatabase : public QObject { Q_OBJECT Q_PROPERTY(bool m_ueConnected READ isConnected WRITE setConnected NOTIFY ueConnectedChanged) private: bool m_ueConneted; inline void setConnected(const bool& ueConnected) { this->m_ueConneted

Adjusting QML Image display size

天大地大妈咪最大 提交于 2019-12-12 10:43:03
问题 I have a QML window with a nested RowLayout . In the inner row I have two images. The source .png files for these images are (intentionally) rather large. When I attempt to set the height property on these images to make them smaller, they are still drawn large. Desired Appearance : Actual Appearance : The only way I have been able to get them to be small is to set the sourceSize.height:100 instead of height:100 ; however, this is not what I want. I want them to be able to scale up and down

Pass binary data from QML to C++

≯℡__Kan透↙ 提交于 2019-12-12 10:24:59
问题 I have a 'binary string' in JavaScript inside of QML, representing raw bytes that I want to pass to C++ (to send over an established socket). I was using code like this: // QML onSomeSignal: { var proto = new MyMessage(); // https://github.com/dcodeIO/protobuf.js var bbuf = proto.encode(); // https://github.com/dcodeIO/bytebuffer.js var bytes = bbuf.toBinary(); messageBridge.send(bytes); } // C++ void MessageBridge::send(const QString& data) { if(m_tcpSocket->state() == QAbstractSocket:

How to stop window size jumping around when forcing fixed aspect ratio?

夙愿已清 提交于 2019-12-12 10:14:43
问题 Here's my test code: import QtQuick 2.4 import QtQuick.Window 2.2 Window { visible: true readonly property int defaultWidth: 700 readonly property int defaultHeight: 500 width: defaultWidth height: defaultHeight readonly property real aspectRatio: defaultWidth / defaultHeight readonly property real scaleFactor: width / defaultWidth onWidthChanged: { var properHeight = Math.round(width / aspectRatio); if ( height !== properHeight ) { height = properHeight } } onHeightChanged: { var properWidth

Best way to access a cpp structure in QML

Deadly 提交于 2019-12-12 08:57:20
问题 I need to pass structures between cpp and QML. If i use property i should create an individual set and get functions, My structure contains minimum 5 members so i felt it's not good to use set and get for all those members. Following is an example of what i am trying to do : MyClass.h #include <QObject> #include <QDebug> using namespace std; struct MyStruct { Q_GADGET int m_val; QString m_name1; QString m_name2; QString m_name3; QString m_name4; Q_PROPERTY(int val MEMBER m_val) Q_PROPERTY

How to take Screenshot of QML application without QQuickView

女生的网名这么多〃 提交于 2019-12-12 07:58:49
问题 I want to grab screen of my QML application. But my root QML object is ApplicationWindow , so I can't use QQuickView to show it. Instead I have to use QQmlApplicationEngine . I know how to take screenshot with QQuickView ( QQuickWindow::grabWindow ), but don't know how to take it with QQmlApplicationEngine . My main file: int main(int argc, char *argv[]) { QApplication app(argc, argv); ApplicationData appData; QQmlApplicationEngine engine; engine.load(QUrl("qrc:///main.qml")); return app.exec

QML ListModel.onDataChanged arguments

白昼怎懂夜的黑 提交于 2019-12-12 04:23:17
问题 I was wondering what kind of data I can use to handle a dataChanged -signal in a QML ListModel . I found out that it has three arguments, two of which are QModelIndices and one is a QVariant(...) . So from the first two (which seems to be the same?) I can get the row, column (which is supposed to be 0), the model itself and uhm... stuff But why do I get it twice? And what is the content of the third? It is not null, but I haven't found a property I could use to retrieve some useful data from

Writing a file manager in QML

北战南征 提交于 2019-12-12 04:18:43
问题 I just started learning QML, with no previous experience in Qt or GUI development in general. My first task is to write a file manager. So far what I like about QML is that I can do design in plain text, but it's been quite challenging finding the way around to achieve even simple things. Currently I use Qt.labs.FolderListModel 2.1 as the work horse for directory listing, and I haven't even touched C++ or PyQt yet, it's purely QML now. So I have a few questions regarding the future path of my

Order of execution PropertyChanges

最后都变了- 提交于 2019-12-12 03:28:01
问题 Is there any documented order of execution of PropertyChanges instances? For example, if there is a State like, State { name: "LOADED" PropertyChanges { target: elem1; width: 10 } PropertyChanges { target: elem2; width: 10 } } is there any specific order which elements width will be setted first? 来源: https://stackoverflow.com/questions/36643036/order-of-execution-propertychanges

Recursion trick in ShaderEffectSource fails when I destroy the source object in onStateChanged

本小妞迷上赌 提交于 2019-12-12 03:27:47
问题 I want a ShaderEffectSource called snapshotter that updates on every change of a source item, but when the source item is destroyed, I want snapshotter to retain the last state of the source item. In my code I use a workaround for a Qt deficiency - setting snapshotter.sourceItem = snapshotter when the previous source item gets destroyed. This works fine when I destroy the old source item e.g. on key press. But when I do it in an onStateChanged handler, I get this error: ShaderEffectSource: