Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick 2.12
- import QtQuick.Window 2.12
- import QtQuick.Controls 2.12
- import com.test.generator 1.0
- Window {
- visible: true
- width: 640
- height: 480
- title: qsTr("Hello World")
- Generator{
- id: generator
- }
- FlickableTextEdit{
- id: edit
- x: 5
- y: 5
- width: 50
- height: 20
- }
- ComboBox{
- x: 80
- y: 5
- id: combo
- property var obj
- model: ListModel {
- id: model
- ListElement { text: "Parameter1" }
- ListElement { text: "Parameter2" }
- }
- onActivated: {
- if(obj) obj.destroy();
- let pref;
- if(currentIndex === 0){
- pref = "1"
- }
- else{
- pref = "2"
- }
- obj = Qt.createQmlObject("import QtQuick 2.12; Connections{ target: generator; onParameter"+pref+"Changed: edit.text = value; }", edit, "Connection");
- }
- }
- }
- //generator.h
- #ifndef GENERATOR_H
- #define GENERATOR_H
- #include <QObject>
- #include <QTimer>
- class Generator : public QObject
- {
- Q_OBJECT
- Q_PROPERTY(double parameter1 READ parameter1 WRITE setParameter1 NOTIFY parameter1Changed)
- Q_PROPERTY(double parameter2 READ parameter2 WRITE setParameter2 NOTIFY parameter2Changed)
- public:
- explicit Generator(QObject *parent = nullptr);
- double parameter1() const;
- void setParameter1(double parameter1);
- double parameter2() const;
- void setParameter2(double parameter2);
- private:
- double m_parameter1;
- double m_parameter2;
- QTimer timer1;
- QTimer timer2;
- signals:
- void parameter1Changed(double value);
- void parameter2Changed(double value);
- public slots:
- void increase();
- void decrease();
- };
- #endif // GENERATOR_H
- //generator.cpp
- #include "generator.h"
- Generator::Generator(QObject *parent) : QObject(parent)
- {
- m_parameter1 = 0;
- m_parameter2 = 100000;
- connect(&timer1, SIGNAL(timeout()), this, SLOT(increase()));
- connect(&timer2, SIGNAL(timeout()), this, SLOT(decrease()));
- timer1.start(1000);
- timer2.start(1000);
- }
- double Generator::parameter1() const
- {
- return m_parameter1;
- }
- void Generator::setParameter1(double ascending)
- {
- m_parameter1 = ascending;
- emit parameter1Changed(m_parameter1);
- }
- double Generator::parameter2() const
- {
- return m_parameter2;
- }
- void Generator::setParameter2(double descending)
- {
- m_parameter2 = descending;
- emit parameter2Changed(m_parameter2);
- }
- void Generator::increase()
- {
- m_parameter1++;
- if(m_parameter1 > 100000) m_parameter1 = 0;
- emit parameter1Changed(m_parameter1);
- }
- void Generator::decrease()
- {
- m_parameter2--;
- if(m_parameter2 < 0) m_parameter2 = 100000;
- emit parameter2Changed(m_parameter2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement