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. Connection on QtGUI and QML?
QtWS25 Last Chance

Connection on QtGUI and QML?

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 3.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.
  • A Offline
    A Offline
    absfrm
    wrote on last edited by
    #1

    Hello
    I designed an application in qml,and imported in QtGUI Application.
    and now , i wanna to make connection in this between .
    For Example , Wen I'm clicked on a button in qml (imported in main window) , my ui->webview got to "......" url.
    can you help me?
    thanks.

    If You Want You Can!

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      I'm not sure I understand your English. I'll assume you meant "when I click a button in QML, I want my webview, declared in C++ (QtWidgets) to go to a certain URL". If that happens to be the case, the answer is quite simple. You can use signal/ slot connections to manage your communication. Or even simple Q_INVOKABLE method.

      For example:

      create a Qt class (it has to inherit from QObject, remember!): say, myText. There, declare something like @ Q_INVOKABLE void setWebViewUrl(const QString &newUrl); @

      add this class to QML by calling @ QDeclarativeView::rootContext()->setContextObject(new myClass *instance()); @ (you have to provide a QDeclarativeView object, of course)

      you can now use this new method inside your QML code, it will be available everywhere. I'll give an example for MouseArea:

      @ MouseArea {
      onClicked: {
      setWebViewUrl("my.new.url.com")
      }
      } @

      That's it. Happy coding :)

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        absfrm
        wrote on last edited by
        #3

        how can i access to setWebViewUrl class from qml file?

        If You Want You Can!

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Re-read 3rd point I've made. It's globally available once you add the QObject that declares it to rootContext.

          (Z(:^

          1 Reply Last reply
          0
          • A Offline
            A Offline
            absfrm
            wrote on last edited by
            #5

            OK
            so thanks

            Best Regard ;)

            If You Want You Can!

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              Cheers.

              If anything is still unclear or doesn't work, don't hesitate to ask.

              If problem is resolved, please add [Solved] at the beginning of this topic's subject.

              (Z(:^

              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