qobject

View, edit and update data (from C++ ) in QML with multiple views, while the Data stays in C++ (subscribe to data)

ⅰ亾dé卋堺 提交于 2019-12-06 06:15:13
I have some data stored in instances of a C++ class (Data.cpp). Now i want to be able to view and edit this data from 2 seperate representations in QML, so that if the values in View1 are changed, the data itself (C++) is changed and the value displayed by View2 as well (because it gets notified when the C++ data changes). Here is what I got so far: Data.h class Data : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) public: Data(std::string name); QString name(); void setName(const QString &n); signals: void nameChanged(); private: std::string

QThread finished() connected to deletelater of a QObject

僤鯓⒐⒋嵵緔 提交于 2019-12-06 01:14:14
问题 I have thought a lot and read lot of articles before asking this question here. None of the articles gave me a proper answer. http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/ QThread* thread = new QThread; Worker* worker = new Worker(); worker->moveToThread(thread); connect(worker, SIGNAL(error(QString)), this, SLOT(errorString(QString))); connect(thread, SIGNAL(started()), worker, SLOT(process())); connect(worker, SIGNAL(finished()), thread,

Tracking mouse move in QGraphicsScene class

不打扰是莪最后的温柔 提交于 2019-12-05 10:06:24
问题 I subclassed QGraphicsScene and added method mouseMoveEvent to handle mouse move event. I created a ruler on top of GraphicsView and have the ruler tracking mouse movement. In the QGraphicsScene::mousemoveEvent I calls mouseMoveEvent of the ruler widget explcitely. The purpose is to have the ruler knows that the current mouse position. Now it seems that QGraphicsScene::mousemoveEvent is not called when I move the mouse. However, I can get it to work if I press the left mouse button and move

Do QObject derived types need a parent QObject?

情到浓时终转凉″ 提交于 2019-12-05 09:31:24
I am writing some Qt class which is derived from QObject , it looks like: class A : public QObject { Q_OBJECT public: A() : QObject() {} ..... } but in several places I saw, that the QObject derived classes all have a parent, like: class A : public QObject { Q_OBJECT public: A(QObject* parent = 0) : QObject(parent) {} ..... } So the question is: do I need a parent or not? What is the difference if I have one, if I have a default one (0) or I don't have at all? Kunal As such you don't need a parent. But setting parent has some advantage in terms of garbage collection. If you set a parent then

Add QObject in the combo box of Qt

谁说我不能喝 提交于 2019-12-04 18:24:36
I have a custom class I created, say MyClass. Now how to add a reference to MyClass's reference as second parameter in the combo box below: this->ui->comboBox->addItem("item-1", ); Purpose is to when item changed even is fired, i want to get that specific class instance of MyClass and process accordingly. First you need to use Q_DECLARE_METATYPE(MyClass*) , so that the type can be used in QVariant . Then you can add the item like this: this->ui->comboBox->addItem("item-1", QVariant::fromValue(myClass)); And get it back: this->ui->combobox->itemData(x).value<MyClass*>(); Above answer syntax is

How to expose C++ structs for computations to Qml

ぃ、小莉子 提交于 2019-12-04 16:41:49
问题 I have the following problem. I am developing a model in C++ and a View in Qml, connecting them via Controllers. In my model I perform multiple calculations. I also offer users of my application the possibility, to write custom event handlers, written in qml. Now I came across a point, where I decided to use Fixed point notation and I have written a corresponding C++ class. Now I want offer the FixedPoint class - including all its operators - to developers, who decide to extend my application

Is it possible to disconnect all of a QObject's connections without deleting it

痞子三分冷 提交于 2019-12-04 16:34:41
问题 I have a QObject A, this is connected to another QObject B. Now I want A to connect to C, a third QObject and to completely disconnect from B. Easy peasy! Trouble is I have a lot of of A's each with their own set of signals and slots (B's/C's are more generic). So far I have been manually making a connect and a disconnect method for each different class type. The methods are basically copies of each other exchanging the connect for disconnect call, going against the don't repeat yourself). So

Qt 5 assign slot with parameters to a QPushButton

。_饼干妹妹 提交于 2019-12-04 09:31:21
问题 I have a Qt application on C++ and I want to assign a slot to a QPushButton. But I want to pass some arguments because I have more than one QPushButton doing similar thing so I want one function but with a parameter in it but Qt keeps saying me that there is no slot like this. Can someone tell me why and how should I do it? Thank you in advance In the .h file I have: (it was private in the beginning but I changed it in searching of the problem) public slots: void handleButton(int row, int col

QThread finished() connected to deletelater of a QObject

时间秒杀一切 提交于 2019-12-04 04:51:29
I have thought a lot and read lot of articles before asking this question here. None of the articles gave me a proper answer. http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/ QThread* thread = new QThread; Worker* worker = new Worker(); worker->moveToThread(thread); connect(worker, SIGNAL(error(QString)), this, SLOT(errorString(QString))); connect(thread, SIGNAL(started()), worker, SLOT(process())); connect(worker, SIGNAL(finished()), thread, SLOT(quit())); connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater())); connect(thread, SIGNAL

Tracking mouse move in QGraphicsScene class

杀马特。学长 韩版系。学妹 提交于 2019-12-03 22:31:55
I subclassed QGraphicsScene and added method mouseMoveEvent to handle mouse move event. I created a ruler on top of GraphicsView and have the ruler tracking mouse movement. In the QGraphicsScene::mousemoveEvent I calls mouseMoveEvent of the ruler widget explcitely. The purpose is to have the ruler knows that the current mouse position. Now it seems that QGraphicsScene::mousemoveEvent is not called when I move the mouse. However, I can get it to work if I press the left mouse button and move it while holding the button. This is not what I'd like to see; I'd like this method is called whenever I