Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Error when using QMetaObject::invokeMethod( /*param*/, /*param*/, Qt::QueuedConnection, Q_ARG(QString, /*param*/))

Error when using QMetaObject::invokeMethod( /*param*/, /*param*/, Qt::QueuedConnection, Q_ARG(QString, /*param*/))

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 1.3k 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
    JJLim
    wrote on last edited by
    #1

    hi, may I know how to use QString as the parameter in the QMetaObject::invokerMethod()?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      What did you try so far? Why do you need this at all?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • J Offline
        J Offline
        JJLim
        wrote on last edited by
        #3

        I wanna update the qml value dynamically actually. I had tried using QTimer and now I find out this method and wonder how to involve QString by using this method

        eyllanescE 1 Reply Last reply
        0
        • J JJLim

          I wanna update the qml value dynamically actually. I had tried using QTimer and now I find out this method and wonder how to involve QString by using this method

          eyllanescE Offline
          eyllanescE Offline
          eyllanesc
          wrote on last edited by
          #4

          @JJLim

          1. If you want to modify any element of QML from C++ then better create a QObject, export it to QML and make a binding.

          2. Connections with QML elements must be of type Qt::DirectConnection so if you want to invoke a method and pass it a string you must use QMetaObject::invokeMethod(obj, "foo", Qt::DirectConnection, Q_ARG(QString, "bar"));

          If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

          jeremy_kJ 1 Reply Last reply
          0
          • eyllanescE eyllanesc

            @JJLim

            1. If you want to modify any element of QML from C++ then better create a QObject, export it to QML and make a binding.

            2. Connections with QML elements must be of type Qt::DirectConnection so if you want to invoke a method and pass it a string you must use QMetaObject::invokeMethod(obj, "foo", Qt::DirectConnection, Q_ARG(QString, "bar"));

            jeremy_kJ Offline
            jeremy_kJ Offline
            jeremy_k
            wrote on last edited by jeremy_k
            #5

            @eyllanesc said in Error when using QMetaObject::invokeMethod( /*param*/, /*param*/, Qt::QueuedConnection, Q_ARG(QString, /*param*/)):

            1. Connections with QML elements must be of type Qt::DirectConnection so if you want to invoke a method and pass it a string you must use QMetaObject::invokeMethod(obj, "foo", Qt::DirectConnection, Q_ARG(QString, "bar"));

            Can you reference anything to support the direct connection requirement? The commit history going back to 4.7 development uses a direct connection for QML property bindings, but that could be for efficiency.

            A test program shows that auto, queued, and blocking queued connections all work with 5.15.5, given the relevant threading restrictions are followed.

            Asking a question about code? http://eel.is/iso-c++/testcase/

            1 Reply Last reply
            0
            • J Offline
              J Offline
              JJLim
              wrote on last edited by
              #6

              Thanks for your advice. I found that I can prevent this error by directly converting it to QString in Q_ARG. The demo is like below

              QMetaObject::invokeMethod( /param/, /param/, Qt::QueuedConnection, Q_ARG(QString, QString::fromStdString("test")));

              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