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. ReferenceError: Can't find variable: because area is overlapped

ReferenceError: Can't find variable: because area is overlapped

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 2 Posters 4.8k Views
  • 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.
  • W Offline
    W Offline
    wspilot
    wrote on last edited by
    #1

    Hi,
    I have an Item with:
    @Connections
    {
    ignoreUnknownSignals : false
    target: tt0 //sender
    onCppSignal: console.log("got signal from cpp:" + nr)
    }@

    Item has child:
    Rectangle...
    Rectangle has child:
    Listbox
    Listbox occupies the complete rectangle area.
    I get the error:
    ReferenceError: Can't find variable: tt0
    When I remove Listbox, the error disappears an the signal works.
    (same happens when Connections is a child of Rectangle)
    I don't understand the rationale behind this.
    Why does the child Listbox (which works OK btw) block functionality of the parent.
    Thanks.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Alek Śmierciak
      wrote on last edited by
      #2

      Some more code would be helpful. Without that it's hard to say why tt0 is called an undeclared variable.

      1 Reply Last reply
      0
      • W Offline
        W Offline
        wspilot
        wrote on last edited by
        #3

        Thanks.
        Sorry, I tried to make it more readable. I have to rephrase my problem, I am getting errors, but the (Connections) signal does work.
        Here is the code:
        @
        import QtQuick 1.1

        Item
        {
        id: topItem
        signal myQmlSignal(int nr, int nr2)
        property alias rectX : rectangle1.x

        function test100(msg)
        {
        console.log(msg)
        helloText.text = msg
        }

        Rectangle
        {
        Connections
        {
        ignoreUnknownSignals : false
        target: tt0 //sender
        onCppSignal: console.log("got signal from cpp:" + nr)
        }

        function test101(msg)
        {
        console.log(msg)
        }
        id: rectangle1
        width: 300
        height: 400
        color: "red"
        radius: 14

        MouseArea
            {
                anchors.fill: parent
                clip: false
                smooth: false
                hoverEnabled: true
               onClicked:
                {
                tt0.cppSlot(11111)
                console.log("top clicked")
                }
            }
        
         Listbox
            {
            listData : myModelData
            }
        

        }
        }@

        app output:

        Starting /home/wim/qt/build-qml1.01_0-Desktop_Qt_5_0_2_GCC_64bit-Debug/qml1...
        Qml debugging is enabled. Only use this in a safe environment!
        file:///home/wim/qt/qml1.01_0/test0.qml:18:3: QML Connections: Cannot assign to non-existent property "onCppSignal"
        file:///home/wim/qt/qml1.01_0/test0.qml:59: ReferenceError: Can't find variable: myModelData
        file:///home/wim/qt/qml1.01_0/test0.qml:21: ReferenceError: Can't find variable: tt0
        file:///home/wim/qt/qml1.01_0/test0.qml:59: ReferenceError: Can't find variable: myModelData
        Hello from C++
        QML function returned: ""
        got signal from cpp:111

        As you can see there is an error, but the signal does work ("got signal from cpp:111")

        When I comment out the Listbox, the signal also works, but the error messages are different:

        Starting /home/wim/qt/build-qml1.01_0-Desktop_Qt_5_0_2_GCC_64bit-Debug/qml1...
        Qml debugging is enabled. Only use this in a safe environment!
        file:///home/wim/qt/qml1.01_0/test0.qml:18:3: QML Connections: Cannot assign to non-existent property "onCppSignal"
        file:///home/wim/qt/qml1.01_0/test0.qml:21: ReferenceError: Can't find variable: tt0
        Hello from C++
        QML function returned: ""
        got signal from cpp:111

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Alek Śmierciak
          wrote on last edited by
          #4

          Are you exposing your C++ 'tt0' class to QML by calling "setContextProperty()":http://qt-project.org/doc/qt-5.0/qtqml/qqmlcontext.html#setContextProperty or by similar means?
          Are you specifying a tt0::cppSignal signal?

          In both your runs, tt0 as well as onCppSignal are undeclared. The only difference is that you don't get reference errors for commented-out ListBox (no surprise).

          1 Reply Last reply
          0
          • W Offline
            W Offline
            wspilot
            wrote on last edited by
            #5

            @context->setContextProperty("tt0", cpp2Qml);
            emit cppSignal(111);
            signals:
            void cppSignal(long nr);@

            Despite the error the signalling works:
            "got signal from cpp:111" in app output?!

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Alek Śmierciak
              wrote on last edited by
              #6

              The signal is being emitted, prompting slot function execution, but the reference error concerns lack of specification for both the object and the signal. Apparently this does not rule out expected behaviour.

              An error is an error, still, and may hinder other functionality. For what kind of help are you asking?

              If what you meant in the first post is how to get rid of ReferenceError for Listbox (unrelated to signal-slot connection, actually), then you need to show the code for Listbox, which as I see it is not a standard element.

              1 Reply Last reply
              0
              • W Offline
                W Offline
                wspilot
                wrote on last edited by
                #7

                Thanks.
                For clarity (one problem at the time), I comment out the Listbox component.
                I still get:
                file:///home/wim/qt/qml1.01_0/test0.qml:18:3: QML Connections: Cannot assign to non-existent property "onCppSignal"
                file:///home/wim/qt/qml1.01_0/test0.qml:21: ReferenceError: Can't find variable: tt0

                You said:
                "the reference error concerns lack of specification for both the object and the signal"
                Shouldn't this (below) be sufficient?
                part of the code:
                @
                MyDeclarativeView Sailfish::createView(const QString &file, Cpp2Qml cpp2Qml)
                {
                MyDeclarativeView *view;//MyDeclarativeView inherits from QDeclarativeView
                view = new MyDeclarativeView;
                view->setSource(QUrl::fromLocalFile(file));// =test0.qml
                QObject object = view->rootObject();
                QDeclarativeEngine
                engine = view->engine();
                QDeclarativeContext *context = engine->rootContext();
                context->setContextProperty("tt0", cpp2Qml);
                ...
                QObject::connect(object, SIGNAL(myQmlSignal(int,int)), cpp2Qml, SLOT(handlemyQmlSignal2int(int,int)) );// not relevant here
                ...
                return view;
                }
                @

                in cpp2qml.h :
                @
                class Cpp2Qml : public QObject
                {
                Q_OBJECT
                public:
                Cpp2Qml();
                ~Cpp2Qml();
                ...
                void test();
                QStringList list;
                public slots:
                void cppSlot(int number);
                void handlemyQmlSignal2int(int nr, int nr2);//not relevant here
                signals:
                void cppSignal(long nr);
                };
                @

                in cpp2qml.cpp :
                @
                void Cpp2Qml::test()
                {
                emit cppSignal(111);
                }
                @

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Alek Śmierciak
                  wrote on last edited by
                  #8

                  After looking at your source code I cannot find the source of the ReferenceError problem. Apparently someone more knowledgeable is needed (or with a keener eye ;-)).

                  Did you attempt to simplify your project structure to isolate the issue at hand more precisely? A project overview might be helpful at the very least.

                  1 Reply Last reply
                  0
                  • W Offline
                    W Offline
                    wspilot
                    wrote on last edited by
                    #9

                    Thanks.
                    Yes, there is more code, not relevant to this issue.
                    When I show all, it becomes hard to read/find the relevant code.
                    Meanwhile I have made some more signal/functions.
                    They all generate errors, but they do work.
                    I have the feeling that is some kind timing problem.
                    First, the variable cannot be found, and possibly it is instantiated or resolved just a split second later...
                    But I am just guessing here.

                    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