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. Cannot include QDeclarative Item
Forum Updated to NodeBB v4.3 + New Features

Cannot include QDeclarative Item

Scheduled Pinned Locked Moved QML and Qt Quick
26 Posts 3 Posters 8.9k Views 1 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.
  • J Offline
    J Offline
    Javeria
    wrote on last edited by
    #3

    But i want to access the Qml objects that is why i was following the above mentioned link, i want to change the image source in the Qml by invoking a c++ functiion that will edit the current image and then access that image property using QDeclarativeitem method in that link, how should i do this?

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #4

      Are you using Qt5 or Qt4 ?

      157

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Javeria
        wrote on last edited by
        #5

        Qt 5.4

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #6

          So donot use QDeclarative* classes. Use Qt5 supported one.

          bq. i want to change the image source in the Qml by invoking a c++ functiion that will edit the current image

          To do this Qt5 way, first go through "Interacting with QML Objects from C++":http://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html and "Integrating QML and C++":http://doc.qt.io/qt-5/qtqml-cppintegration-topic.html.

          157

          1 Reply Last reply
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #7

            To clarify p3c0's words:

            • Classes named QDeclarative[X] are obsolete. You should use them with Qt 4, but you should not use them with Qt 5.
            • For Qt 5, use classes named QQml[X] and QQuick[X].

            [quote author="Javeria" date="1424320806"]i m trying to initialize QtDEclarative objects, i was following this link:
            Link: http://qt-project.org/doc/qt-4.8/qtbinding.html
            [/quote]That link is for Qt 4. Do not follow it.

            Use p3c0's links instead.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Javeria
              wrote on last edited by
              #8

              Thanks a lot for the guidance but i dont have a lot of time and i have like an hour to complete this so if you guys could help in the setting of context property that i cant seem to set context propert its giving me this: error: C2227: left of '->setContextProperty' must point to class/struct/union/generic type
              when i declare this:
              @ QQmlEngine eng;
              DetectSquares m;
              eng.rootContext()->setContextProperty("m",&m);
              QQmlComponent component(&engine, QUrl::fromLocalFile("main.qml"));
              component.create();
              @

              1 Reply Last reply
              0
              • JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #9

                [quote author="Javeria" date="1424331653"]error: C2227: left of '- >setContextProperty' must point to class/struct/union/generic type[/quote]That means your compiler doesn't recognize the item on the left of '->setContextProperty'. Did you #include <QQmlContext>?

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  Javeria
                  wrote on last edited by
                  #10

                  Okay done!!, but i have to now call DetectSquares objects function iside QML file, but its givng me syntax error and i dont know how should i set the signal its really confusing :
                  Here s is the DetectSqaure.h
                  @#ifndef DETECTSQUARES_H
                  #define DETECTSQUARES_H
                  #include "opencv2/highgui/highgui.hpp"
                  #include "opencv2/imgproc/imgproc.hpp"

                  #include <iostream>

                  using namespace cv;
                  using namespace std;

                  #include <QObject>

                  class DetectSquares: public QObject
                  {
                  Q_OBJECT
                  public:
                  double angle(Point pt1, Point pt2, Point pt0);
                  void findSquares(Mat image);
                  static void drawSquares(Mat& image, const vector<vector<Point> >& squares);
                  void Detect(Mat image);
                  bool proximity(Size rect1, Size rect2);
                  Rect proximity_rect(Rect rect1, Rect rect2);
                  Rect is_a_box(Point cp);
                  vector<vector<Point>> squares;
                  Mat image;
                  Point prev_pointer;
                  vector<Rect> Detected;
                  int y;

                  };

                  #endif // DETECTSQUARES_H
                  @
                  Hers the Qml Code:
                  @import QtQuick 2.4
                  import QtQuick.Controls 1.3
                  import QtQuick.Window 2.2
                  import QtQuick.Dialogs 1.2
                  import QtQuick 2.0
                  ApplicationWindow {
                  title: qsTr("Sketch_it")
                  width: 1500
                  height: 1000
                  visible: true
                  property var imagesListModel: ["file:/original.jpg","file:/11.jpg","file:/test (1).jpg","file:/test (2).jpg","file:/test (3).jpg","file:/test (4).jpg","file:/test (5).jpg"]
                  ListView {
                  id: imagesList
                  anchors.fill:parent
                  spacing:25
                  orientation: Qt.Vertical
                  model: imagesListModel
                  delegate: Image {
                  objectName: "Displayimage"
                  width: 75
                  height: 100
                  source: imagesListModel[index]
                  Text{
                  text:"Sketch"+(index+1)
                  }

                           MouseArea {
                               anchors.fill: parent
                  
                               onClicked: {
                                  main.source=imagesListModel[index]
                                  Component.OnCompleted:{
                                   m.Detect();
                                   }
                                 // console.log("User select '"+"' image");
                               }
                           }
                      }
                  }
                  Image{
                      id:main
                      width: 700
                      height: 600
                  
                     // source:"file:/test (6).jpg"
                      anchors.centerIn: parent
                      MouseArea{
                        anchors.fill:parent
                         onClicked: {
                  
                  
                             console.log(mouseX+" "+mouseY);
                       }
                      }
                  }
                  

                  }
                  @

                  1 Reply Last reply
                  0
                  • p3c0P Offline
                    p3c0P Offline
                    p3c0
                    Moderators
                    wrote on last edited by
                    #11

                    You will need to make those methods "Q_INVOKABLE":http://doc.qt.io/qt-5/qobject.html#Q_INVOKABLE. An example of how to access them is "here":http://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.html#exposing-methods-including-qt-slots.
                    But beware that QML recognizes only the "following":http://doc.qt.io/qt-5/qtqml-cppintegration-data.html#basic-qt-data-types data types. So it wont recongnize those OpenCV's user defined data types.

                    157

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      Javeria
                      wrote on last edited by
                      #12

                      I ve kinda follwoed it, i dnt have enough time , i have 5 min, heres the code, its giving me syntax error when i use Component.onCompleted:
                      @import QtQuick 2.4
                      import QtQuick.Controls 1.3
                      import QtQuick.Window 2.2
                      import QtQuick.Dialogs 1.2
                      import QtQuick 2.0
                      ApplicationWindow {
                      title: qsTr("Sketch_it")
                      width: 1500
                      height: 1000
                      visible: true
                      property var imagesListModel: ["file:/original.jpg","file:/11.jpg","file:/test (1).jpg","file:/test (2).jpg","file:/test (3).jpg","file:/test (4).jpg","file:/test (5).jpg"]
                      ListView {
                      id: imagesList
                      anchors.fill:parent
                      spacing:25
                      orientation: Qt.Vertical
                      model: imagesListModel
                      delegate: Image {
                      objectName: "Displayimage"
                      width: 75
                      height: 100
                      source: imagesListModel[index]
                      Text{
                      text:"Sketch"+(index+1)
                      }

                               MouseArea {
                                   anchors.fill: parent
                      
                                   onClicked: {
                                      main.source=imagesListModel[index]
                                      Component.OnCompleted:
                                       {
                                           m.Detect();
                                       }
                                     // console.log("User select '"+"' image");
                                   }
                               }
                          }
                      }
                      Image{
                          id:main
                          width: 700
                          height: 600
                      
                         // source:"file:/test (6).jpg"
                          anchors.centerIn: parent
                          MouseArea{
                            anchors.fill:parent
                             onClicked: {
                      
                      
                                 console.log(mouseX+" "+mouseY);
                           }
                          }
                      }
                      

                      }
                      @

                      1 Reply Last reply
                      0
                      • p3c0P Offline
                        p3c0P Offline
                        p3c0
                        Moderators
                        wrote on last edited by
                        #13

                        Ofcourse it will.
                        @
                        void Detect(Mat image);
                        @

                        Takes an argument and you are not supplying it. Plus it takes an argument not recognized by QML. You will need to find another way to pass the data from QML to C++ and which is recognized by both.

                        157

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          Javeria
                          wrote on last edited by
                          #14

                          Okay but there is still syntax error in this
                          @Component.OnCompleted:
                          {

                            }@
                          
                          1 Reply Last reply
                          0
                          • JKSHJ Offline
                            JKSHJ Offline
                            JKSH
                            Moderators
                            wrote on last edited by
                            #15
                            • Component.onCompleted is a signal handler.
                            • onClicked is a signal handler.

                            You cannot put a signal handler inside another signal handler. You need to move Component.onCompleted up one level, at least.

                            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                            1 Reply Last reply
                            0
                            • p3c0P Offline
                              p3c0P Offline
                              p3c0
                              Moderators
                              wrote on last edited by
                              #16

                              [quote author="JKSH" date="1424387370"]* Component.onCompleted is a signal handler.

                              • onClicked is a signal handler.

                              You cannot put a signal handler inside another signal handler. You need to move Component.onCompleted up one level, at least.
                              [/quote]

                              Right. I missed that one.

                              157

                              1 Reply Last reply
                              0
                              • J Offline
                                J Offline
                                Javeria
                                wrote on last edited by
                                #17

                                Okay but i have two call two c++ functions, and one should be called when the user clicks on the main image so i cant use component.oncompleted thn?

                                1 Reply Last reply
                                0
                                • p3c0P Offline
                                  p3c0P Offline
                                  p3c0
                                  Moderators
                                  wrote on last edited by
                                  #18

                                  Call that function in onClicked event handler. Component.onCompleted is called after the object has been instantiated. You can call the function inside it also but since you need to do it on click, call it inside onClicked.

                                  157

                                  1 Reply Last reply
                                  0
                                  • JKSHJ Offline
                                    JKSHJ Offline
                                    JKSH
                                    Moderators
                                    wrote on last edited by
                                    #19

                                    [quote author="Javeria" date="1424418592"]Okay but i have two call two c++ functions, and one should be called when the user clicks on the main image so i cant use component.oncompleted thn?[/quote]As the name implies, Component.onCompleted runs when the component has finished loading.

                                    Do you want your function to be called when the component finishes loading?

                                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                    1 Reply Last reply
                                    0
                                    • J Offline
                                      J Offline
                                      Javeria
                                      wrote on last edited by
                                      #20

                                      And also i have changed my detectsquare function's parameters to Qimage
                                      so that i could use the current selected image in that function but i dont understand how i should do that in QML? As i cant use Qimage object in QML

                                      1 Reply Last reply
                                      0
                                      • p3c0P Offline
                                        p3c0P Offline
                                        p3c0
                                        Moderators
                                        wrote on last edited by
                                        #21

                                        Since you already have paths, you can just send the path string from QML to C++ and then there access that image.

                                        157

                                        1 Reply Last reply
                                        0
                                        • J Offline
                                          J Offline
                                          Javeria
                                          wrote on last edited by
                                          #22

                                          But I want to edit that image and send it back to qml so that it displays it in the ui

                                          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