Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Unable to assign [undefined] to QString

Unable to assign [undefined] to QString

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 981 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    enzobarrett
    wrote on last edited by enzobarrett
    #1

    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

    #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

    #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

    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
            }
        }
    }
    
    

    Thank you for your help!
    Also this error is occurring on the text object

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Since you are developing a KDE plasmoid, you should rather bring this question to the KDE folks.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      E 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Since you are developing a KDE plasmoid, you should rather bring this question to the KDE folks.

        E Offline
        E Offline
        enzobarrett
        wrote on last edited by
        #3

        @SGaist thank you for your reply. I'll pass my question on to the KDE folk!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved