Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Public Functions qt++ to qml

Public Functions qt++ to qml

Scheduled Pinned Locked Moved Unsolved Language Bindings
5 Posts 3 Posters 2.3k 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.
  • Dante LeonciniD Offline
    Dante LeonciniD Offline
    Dante Leoncini
    wrote on last edited by Dante Leoncini
    #1

    I 'm trying to get values ​​of public functions
    for example. I want to know the number of screens connected with "screenCount ()"

    if (1 == screenCount()){celular.show();};
    

    or if I want the position of the mouse in QML
    viewer.rootContext()->setContextProperty("anchoSalida", QMouseEvent->globalX());

    all these examples fail. as it should really be written ?

    raven-worxR 1 Reply Last reply
    0
    • Dante LeonciniD Dante Leoncini

      I 'm trying to get values ​​of public functions
      for example. I want to know the number of screens connected with "screenCount ()"

      if (1 == screenCount()){celular.show();};
      

      or if I want the position of the mouse in QML
      viewer.rootContext()->setContextProperty("anchoSalida", QMouseEvent->globalX());

      all these examples fail. as it should really be written ?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Dante-Leoncini

      you mean something like the following?

      class MyFunctionsProvider : QObject
      {
          Q_OBJECT
      
      public:
           MyFunctionsProvider ( QObject* parent = 0 ) : QObject(parent)
           {
           }
      
           Q_INVOKABLE int GetScreenCount() const
           {
                   QList<QScreen *> screens = QGuiApplication::screens();
                  return screen.count();
           }
      
           Q_INVOKABLE QPoint GlobalCursorPos() const
           {
                  return QCursor::pos();
           }
      };
      
      ...
      
      viewer.rootContext()->setContextProperty("MyFunctions", new MyFunctionsProvider(viewer.rootContext()) );
      

      In QML you can do then:

      MyFunctions.GetScreenCount()
      MyFunctions.GlobalCursorPos()
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      Dante LeonciniD 1 Reply Last reply
      1
      • raven-worxR raven-worx

        @Dante-Leoncini

        you mean something like the following?

        class MyFunctionsProvider : QObject
        {
            Q_OBJECT
        
        public:
             MyFunctionsProvider ( QObject* parent = 0 ) : QObject(parent)
             {
             }
        
             Q_INVOKABLE int GetScreenCount() const
             {
                     QList<QScreen *> screens = QGuiApplication::screens();
                    return screen.count();
             }
        
             Q_INVOKABLE QPoint GlobalCursorPos() const
             {
                    return QCursor::pos();
             }
        };
        
        ...
        
        viewer.rootContext()->setContextProperty("MyFunctions", new MyFunctionsProvider(viewer.rootContext()) );
        

        In QML you can do then:

        MyFunctions.GetScreenCount()
        MyFunctions.GlobalCursorPos()
        
        Dante LeonciniD Offline
        Dante LeonciniD Offline
        Dante Leoncini
        wrote on last edited by Dante Leoncini
        #3

        @raven-worx

        thanks for the reply. For the width and height of the screen to solve it so:

        viewer.rootContext()->setContextProperty("altoSalida", WidgetEscritorio->screenGeometry(1).height());
            viewer.rootContext()->setContextProperty("anchoSalida", WidgetEscritorio->screenGeometry(1).width());
        

        but when I wanted to do the same with the position of the mouse did not work .
        Try to use your code to get the coordinates :

        class MyFunctionsProvider : QObject
        {
            Q_OBJECT
        
        public:
             MyFunctionsProvider ( QObject* parent = 0 ) : QObject(parent)
             {
             }
        
             Q_INVOKABLE QPoint GlobalCursorPos() const
             {
                    return QCursor::pos();
             }
        };
        
        viewer.rootContext()->setContextProperty("MyFunctions", new MyFunctionsProvider(viewer.rootContext()));
        

        But when I try to compile get the error: 'QObject' is an inaccessible base of 'MyFunctionsProvider'

        I 'm looking for because it is. I lack even practiced in qt c ++
        (translated with google)

        edit:
        missing the word "public" in class MyFunctionsProvider : public QObject
        but now comes another error: undefined reference to `vtable for MyFunctionsProvider'

        raven-worxR N 2 Replies Last reply
        0
        • Dante LeonciniD Dante Leoncini

          @raven-worx

          thanks for the reply. For the width and height of the screen to solve it so:

          viewer.rootContext()->setContextProperty("altoSalida", WidgetEscritorio->screenGeometry(1).height());
              viewer.rootContext()->setContextProperty("anchoSalida", WidgetEscritorio->screenGeometry(1).width());
          

          but when I wanted to do the same with the position of the mouse did not work .
          Try to use your code to get the coordinates :

          class MyFunctionsProvider : QObject
          {
              Q_OBJECT
          
          public:
               MyFunctionsProvider ( QObject* parent = 0 ) : QObject(parent)
               {
               }
          
               Q_INVOKABLE QPoint GlobalCursorPos() const
               {
                      return QCursor::pos();
               }
          };
          
          viewer.rootContext()->setContextProperty("MyFunctions", new MyFunctionsProvider(viewer.rootContext()));
          

          But when I try to compile get the error: 'QObject' is an inaccessible base of 'MyFunctionsProvider'

          I 'm looking for because it is. I lack even practiced in qt c ++
          (translated with google)

          edit:
          missing the word "public" in class MyFunctionsProvider : public QObject
          but now comes another error: undefined reference to `vtable for MyFunctionsProvider'

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @Dante-Leoncini said in Public Functions qt++ to qml:

          missing the word "public" in class MyFunctionsProvider : public QObject

          yes, i missed hat.

          but now comes another error: undefined reference to `vtable for MyFunctionsProvider'

          strange. Is the code you've posted really all you are using? Or did you stip something out?
          Try a clean rebuilt maybe.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • Dante LeonciniD Dante Leoncini

            @raven-worx

            thanks for the reply. For the width and height of the screen to solve it so:

            viewer.rootContext()->setContextProperty("altoSalida", WidgetEscritorio->screenGeometry(1).height());
                viewer.rootContext()->setContextProperty("anchoSalida", WidgetEscritorio->screenGeometry(1).width());
            

            but when I wanted to do the same with the position of the mouse did not work .
            Try to use your code to get the coordinates :

            class MyFunctionsProvider : QObject
            {
                Q_OBJECT
            
            public:
                 MyFunctionsProvider ( QObject* parent = 0 ) : QObject(parent)
                 {
                 }
            
                 Q_INVOKABLE QPoint GlobalCursorPos() const
                 {
                        return QCursor::pos();
                 }
            };
            
            viewer.rootContext()->setContextProperty("MyFunctions", new MyFunctionsProvider(viewer.rootContext()));
            

            But when I try to compile get the error: 'QObject' is an inaccessible base of 'MyFunctionsProvider'

            I 'm looking for because it is. I lack even practiced in qt c ++
            (translated with google)

            edit:
            missing the word "public" in class MyFunctionsProvider : public QObject
            but now comes another error: undefined reference to `vtable for MyFunctionsProvider'

            N Offline
            N Offline
            Naahmi
            wrote on last edited by
            #5

            @Dante-Leoncini said in Public Functions qt++ to qml:

            but now comes another error: undefined reference to `vtable for MyFunctionsProvider'

            Hi,
            you need to run qmake.

            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