So to fix my problem I have to rename "siema" and "keppo" declarations in main?
I now have sth like this, but still not working.
#ifndef KEPPOXD_H
#define KEPPOXD_H
#include <QObject>
#include <QDebug>
#include <siema.h>
{
Q_OBJECT
public:
explicit keppoxd
(QObject *parent
= nullptr
);
siema siema;
signals:
public slots:
};
#endif // KEPPOXD_H
#ifndef KEPPOXD_H
#define KEPPOXD_H
#include <QObject>
#include <QDebug>
#include <siema.h>
class keppoxd : public QObject
{
Q_OBJECT
public:
explicit keppoxd(QObject *parent = nullptr);
siema siema;
signals:
void textChanged(QString);
public slots:
void setWindowName(QString value);
};
#endif // KEPPOXD_H
To copy to clipboard, switch view to plain text mode
#ifndef SIEMA_H
#define SIEMA_H
#include <QObject>
#include <QDebug>
{
Q_OBJECT
public:
explicit siema
(QObject *parent
= nullptr
);
signals:
public slots:
void check();
};
#endif // SIEMA_H
#ifndef SIEMA_H
#define SIEMA_H
#include <QObject>
#include <QDebug>
class siema : public QObject
{
Q_OBJECT
public:
explicit siema(QObject *parent = nullptr);
QString name = "old";
signals:
public slots:
void setWindowName(QString value);
void check();
};
#endif // SIEMA_H
To copy to clipboard, switch view to plain text mode
#include "keppoxd.h"
{
connect(this,
SIGNAL (textChanged
(QString)),
&siema,
SLOT(setWindowName
(QString)));
}
void keppoxd
::setWindowName(QString value
) {
siema.name = value;
qDebug() << "siema.name value from keppo class " << siema.name;
emit textChanged(value);
}
#include "keppoxd.h"
keppoxd::keppoxd(QObject *parent) : QObject(parent)
{
connect(this, SIGNAL (textChanged(QString)), &siema, SLOT(setWindowName(QString)));
}
void keppoxd::setWindowName(QString value)
{
siema.name = value;
qDebug() << "siema.name value from keppo class " << siema.name;
emit textChanged(value);
}
To copy to clipboard, switch view to plain text mode
#include "siema.h"
{
}
void siema
::setWindowName(QString value
) {
name = value;
}
void siema::check()
{
qDebug() << "siema value " << name;
}
#include "siema.h"
siema::siema(QObject *parent) : QObject(parent)
{
}
void siema::setWindowName(QString value)
{
name = value;
}
void siema::check()
{
qDebug() << "siema value " << name;
}
To copy to clipboard, switch view to plain text mode
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QSettings>
#include <QDir>
#include <QDebug>
#include <keppoxd.h>
#include <siema.h>
#include <QQmlContext>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
//QSettings* settings;
/*if(QFileInfo::exists(QDir::currentPath() + "/my_config_file.ini")){
qDebug() << "istnieje";
}
else{
qDebug() << "nie istnieje";
settings = new QSettings(QDir::currentPath() + "/my_config_file.ini", QSettings::IniFormat);
settings->setValue("test", "value");
settings->setValue("Button", 1);
settings->sync();
} */
siema siemaqml;
keppoxd keppoqml;
QQmlApplicationEngine engine;
const QUrl url
(QStringLiteral
("qrc:/main.qml"));
QObject::connect(&engine,
&QQmlApplicationEngine
::objectCreated,
if (!obj && url == objUrl)
}, Qt::QueuedConnection);
engine.load(url);
QQmlContext *ctx = engine.rootContext();
ctx->setContextProperty("Siema", &siemaqml);
ctx->setContextProperty("Keppo", &keppoqml);
return app.exec();
}
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QSettings>
#include <QDir>
#include <QDebug>
#include <keppoxd.h>
#include <siema.h>
#include <QQmlContext>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
//QSettings* settings;
/*if(QFileInfo::exists(QDir::currentPath() + "/my_config_file.ini")){
qDebug() << "istnieje";
}
else{
qDebug() << "nie istnieje";
settings = new QSettings(QDir::currentPath() + "/my_config_file.ini", QSettings::IniFormat);
settings->setValue("test", "value");
settings->setValue("Button", 1);
settings->sync();
} */
siema siemaqml;
keppoxd keppoqml;
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
QQmlContext *ctx = engine.rootContext();
ctx->setContextProperty("Siema", &siemaqml);
ctx->setContextProperty("Keppo", &keppoqml);
return app.exec();
}
To copy to clipboard, switch view to plain text mode
import QtQuick 2.9
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
TextInput {
id: textInput
x: 48
y: 58
width: 80
height: 20
text: qsTr("Text Input")
font.pixelSize: 12
onTextEdited:{
Keppo.setWindowName(textInput.text);
Siema.check();
}
}
Rectangle {
id: rectangle
x: 276
y: 41
width: 200
height: 200
color: "#e30a0a"
MouseArea {
id: mouseArea
x: 0
y: 0
width: 200
height: 200
onClicked:{
Keppo.setWindowName(textInput.text);
Siema.check();
}
}
}
}
import QtQuick 2.9
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
TextInput {
id: textInput
x: 48
y: 58
width: 80
height: 20
text: qsTr("Text Input")
font.pixelSize: 12
onTextEdited:{
Keppo.setWindowName(textInput.text);
Siema.check();
}
}
Rectangle {
id: rectangle
x: 276
y: 41
width: 200
height: 200
color: "#e30a0a"
MouseArea {
id: mouseArea
x: 0
y: 0
width: 200
height: 200
onClicked:{
Keppo.setWindowName(textInput.text);
Siema.check();
}
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks