Reply to topic

Unable to assign [undefined] to QString

enzobarrett
Registered Member
Posts
1
Karma
0
Hello,

I am developing a kde plasmoid and cannot get basic communication between cpp and qml. I think everything is returning the correct type but I am still getting undefined. Here are my files:

unixtime.h
Code: Select all
#ifndef UNIXTIME_H
#define UNIXTIME_H


#include <Plasma/Applet>

class unixtime : public Plasma::Applet
{
    Q_OBJECT
    Q_PROPERTY(QString nativeText READ nativeText CONSTANT)

public:
    unixtime( QObject *parent, const QVariantList &args );
    ~unixtime();
    QString nativeText() const;
    QString text() const;

private:
    QString m_nativeText;
};

#endif



unixtime.cpp
Code: Select all
#include "unixtime.h"
#include <klocalizedstring.h>
#include <QString>

unixtime::unixtime(QObject *parent, const QVariantList &args)
    : Plasma::Applet(parent, args),
      m_nativeText(i18n("Text coming from C++ plugin"))
{
}

unixtime::~unixtime()
{
}

QString unixtime::nativeText() const
{
    return QString("Test");
    return m_nativeText;
}

QString unixtime::text() const
{
    return QString("test");
}

K_EXPORT_PLASMA_APPLET_WITH_JSON(unixtime, unixtime, "metadata.json")

#include "unixtime.moc"



main.qml
Code: Select all
import QtQuick 2.1
import QtQuick.Layouts 1.1
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.components 2.0 as PlasmaComponents

Item {
    Plasmoid.fullRepresentation: ColumnLayout {
        anchors.fill: parent
        Image {
            Layout.fillHeight: true
            Layout.fillWidth: true
            fillMode: Image.PreserveAspectFit
            source: "../images/pairs.svgz"
        }
        PlasmaComponents.Label {
            Layout.alignment: Qt.AlignCenter
            text: plasmoid.nativeInterface.text  //ERROR OCCURS HERE, AM I CALLING THE CPP WRONG?
        }
    }
}


Thank you for your help!
This error is occurring on the text object.
Luc4
Registered Member
Posts
6
Karma
0
Never used those classes, but assuming plasmoid.nativeInterface refers to an instance of unixtime, "text" does not seem to be a property.

 
Reply to topic

Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], boudewijn, davide445, Google [Bot], hiteshshah, madkhoram, Majestic-12 [Bot], Mamarok, millaan, raphaelra