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. Passing Arguments to the Function
Forum Updated to NodeBB v4.3 + New Features

Passing Arguments to the Function

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 1.1k 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.
  • N najlou

    @JonB
    thank you for your answer I tried your method with &this->ui->label_2
    but it didn't work, it's always the same error

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #4

    @najlou Please post the whole error you get.
    Also, as @JonB already wrote: other threads are not allowed to change UI elements. So, why do you want to pass the label to the thread?

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    N 1 Reply Last reply
    1
    • jsulmJ jsulm

      @najlou Please post the whole error you get.
      Also, as @JonB already wrote: other threads are not allowed to change UI elements. So, why do you want to pass the label to the thread?

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

      @jsulm because I will need to use the QLabel, which I can't figure out if I delete for example "this-> cameraAva" or "this-> CameraImageCaptureAva" there is no more this error I think we are limited by a number of variables but is there a solution please ?
      error : no matching function for call to 'run'

      jsulmJ 1 Reply Last reply
      0
      • N najlou

        @jsulm because I will need to use the QLabel, which I can't figure out if I delete for example "this-> cameraAva" or "this-> CameraImageCaptureAva" there is no more this error I think we are limited by a number of variables but is there a solution please ?
        error : no matching function for call to 'run'

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #6

        @najlou said in Passing Arguments to the Function:

        because I will need to use the QLabel

        In what way do you need to use it? Do you want to get its text (then simply pass the text instead of whole QLabel), or do you want to change it? If you want to change it then, as already said two times, you are not allowed to do so in other threads than GUI thread!

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        N 1 Reply Last reply
        0
        • jsulmJ jsulm

          @najlou said in Passing Arguments to the Function:

          because I will need to use the QLabel

          In what way do you need to use it? Do you want to get its text (then simply pass the text instead of whole QLabel), or do you want to change it? If you want to change it then, as already said two times, you are not allowed to do so in other threads than GUI thread!

          N Offline
          N Offline
          najlou
          wrote on last edited by najlou
          #7

          @jsulm but why when I add the QLabel and delete for example "this-> cameraAva" or "this-> CameraImageCaptureAva" there is no more error

          jsulmJ 1 Reply Last reply
          0
          • N najlou

            @jsulm but why when I add the QLabel and delete for example "this-> cameraAva" or "this-> CameraImageCaptureAva" there is no more error

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #8

            @najlou I don't know, you did not post WHOLE error yet...

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            N 1 Reply Last reply
            0
            • jsulmJ jsulm

              @najlou I don't know, you did not post WHOLE error yet...

              N Offline
              N Offline
              najlou
              wrote on last edited by najlou
              #9

              @jsulm it's just : no matching function for call to 'run' when I exceed 6 variables

              jsulmJ 1 Reply Last reply
              0
              • N najlou

                @jsulm it's just : no matching function for call to 'run' when I exceed 6 variables

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #10

                @najlou Please open "Compile Output" tab in QtCreator and check whether the error message provides more information there.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                N 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @najlou Please open "Compile Output" tab in QtCreator and check whether the error message provides more information there.

                  N Offline
                  N Offline
                  najlou
                  wrote on last edited by
                  #11

                  @jsulm ../Rover/rover.cpp:612:45: warning: unused parameter ‘label_2’ [-Wunused-parameter]
                  QCamera cameraArriere, QLabel label_2
                  ~~^
                  ../Rover/rover.cpp: In member function ‘void Rover::on_Lidar_clicked()’:
                  ../Rover/rover.cpp:734:59: error: no matching function for call to ‘run(void (&)(QString, QCamera
                  , QCameraImageCapture
                  , QCameraImageCapture*, QCamera*, QLabel*), QString&, QCamera*&, QCameraImageCapture*&, QCameraImageCapture*&, QCamera*&, QLabel*&)’
                  this->ui->label_2);
                  ^
                  In file included from /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/QtConcurrent:16,
                  from ../Rover/rover.cpp:17:
                  /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:72:12: note: candidate: ‘template<class T> QFuture<T> QtConcurrent::run(T (*)())’
                  QFuture<T> run(T (functionPointer)())
                  ^~~
                  /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:72:12: note: template argument deduction/substitution failed:
                  ../Rover/rover.cpp:734:59: note: candidate expects 0 arguments, 6 provided
                  this->ui->label_2);
                  ^
                  In file included from /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/QtConcurrent:16,
                  from ../Rover/rover.cpp:17:
                  /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:77:12: note: candidate: ‘template<class T, class Param1, class Arg1> QFuture<T> QtConcurrent::run(T (
                  )(Param1), const Arg1&)’
                  QFuture<T> run(T (functionPointer)(Param1), const Arg1 &arg1)
                  ^~~
                  /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:77:12: note: template argument deduction/substitution failed:
                  ../Rover/rover.cpp:734:59: note: candidate expects 1 argument, 6 provided
                  this->ui->label_2);
                  ^
                  In file included from /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/QtConcurrent:16,
                  from ../Rover/rover.cpp:17:
                  /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:82:12: note: candidate: ‘template<class T, class Param1, class Arg1, class Param2, class Arg2> QFuture<T> QtConcurrent::run(T (
                  )(Param1, Param2), const Arg1&, const Arg2&)’
                  QFuture<T> run(T (functionPointer)(Param1, Param2), const Arg1 &arg1, const Arg2 &arg2)
                  ^~~
                  /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:82:12: note: template argument deduction/substitution failed:
                  ../Rover/rover.cpp:734:59: note: candidate expects 2 arguments, 6 provided
                  this->ui->label_2);
                  ^
                  In file included from /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/QtConcurrent:16,
                  from ../Rover/rover.cpp:17:
                  /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:87:12: note: candidate: ‘template<class T, class Param1, class Arg1, class Param2, class Arg2, class Param3, class Arg3> QFuture<T> QtConcurrent::run(T (
                  )(Param1, Param2, Param3), const Arg1&, const Arg2&, const Arg3&)’
                  QFuture<T> run(T (functionPointer)(Param1, Param2, Param3), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3)
                  ^~~
                  /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:87:12: note: template argument deduction/substitution failed:
                  ../Rover/rover.cpp:734:59: note: candidate expects 3 arguments, 6 provided
                  this->ui->label_2);
                  ^
                  In file included from /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/QtConcurrent:16,
                  from ../Rover/rover.cpp:17:
                  /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:92:12: note: candidate: ‘template<class T, class Param1, class Arg1, class Param2, class Arg2, class Param3, class Arg3, class Param4, class Arg4> QFuture<T> QtConcurrent::run(T (
                  )(Param1, Param2, Param3, Param4), const Arg1&, const Arg2&, const Arg3&, const Arg4&)’
                  QFuture<T> run(T (functionPointer)(Param1, Param2, Param3, Param4), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4)
                  ^~~
                  /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:92:12: note: template argument deduction/substitution failed:
                  ../Rover/rover.cpp:734:59: note: candidate expects 4 arguments, 6 provided
                  this->ui->label_2);
                  ^
                  In file included from /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/QtConcurrent:16,
                  from ../Rover/rover.cpp:17:
                  /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:97:12: note: candidate: ‘template<class T, class Param1, class Arg1, class Param2, class Arg2, class Param3, class Arg3, class Param4, class Arg4, class Param5, class Arg5> QFuture<T> QtConcurrent::run(T (
                  )(Param1, Param2, Param3, Param4, Param5), const Arg1&, const Arg2&, const Arg3&, const Arg4&, const Arg5&)’
                  QFuture<T> run(T (*functionPointer)(Param1, Param2, Param3, Param4, Param5), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5)
                  ^~~
                  /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:97:12: note: template argument deduction/substitution failed:
                  ../Rover/rover.cpp:734:59: note: candidate expects 5 arguments, 6 provided
                  this->ui->label_2);
                  ^
                  In file included from /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/QtConcurrent:16,
                  from ../Rover/rover.cpp:17:
                  /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:105:6: note: candidate: ‘template<class Functor> typename std::enable_if<(! QtPrivate::HasResultType<MapFunctor>::Value), QFuture<decltype (functor())> >::type QtConcurrent::run(Functor)’
                  auto run(Functor functor) -> typename std::enable_if<!QtPrivate::HasResultType<Functor>::Value, QFuture<decltype(functor())>>::type
                  ^~~
                  /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:105:6: note: template argument deduction/substitution failed:
                  ../Rover/rover.cpp:734:59: note: candidate expects 1 argument, 7 provided
                  this->ui->label_2);
                  ^
                  In file included from /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/QtConcurrent:16,
                  from ../Rover/rover.cpp:17:

                  jsulmJ 1 Reply Last reply
                  0
                  • N najlou

                    @jsulm ../Rover/rover.cpp:612:45: warning: unused parameter ‘label_2’ [-Wunused-parameter]
                    QCamera cameraArriere, QLabel label_2
                    ~~^
                    ../Rover/rover.cpp: In member function ‘void Rover::on_Lidar_clicked()’:
                    ../Rover/rover.cpp:734:59: error: no matching function for call to ‘run(void (&)(QString, QCamera
                    , QCameraImageCapture
                    , QCameraImageCapture*, QCamera*, QLabel*), QString&, QCamera*&, QCameraImageCapture*&, QCameraImageCapture*&, QCamera*&, QLabel*&)’
                    this->ui->label_2);
                    ^
                    In file included from /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/QtConcurrent:16,
                    from ../Rover/rover.cpp:17:
                    /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:72:12: note: candidate: ‘template<class T> QFuture<T> QtConcurrent::run(T (*)())’
                    QFuture<T> run(T (functionPointer)())
                    ^~~
                    /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:72:12: note: template argument deduction/substitution failed:
                    ../Rover/rover.cpp:734:59: note: candidate expects 0 arguments, 6 provided
                    this->ui->label_2);
                    ^
                    In file included from /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/QtConcurrent:16,
                    from ../Rover/rover.cpp:17:
                    /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:77:12: note: candidate: ‘template<class T, class Param1, class Arg1> QFuture<T> QtConcurrent::run(T (
                    )(Param1), const Arg1&)’
                    QFuture<T> run(T (functionPointer)(Param1), const Arg1 &arg1)
                    ^~~
                    /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:77:12: note: template argument deduction/substitution failed:
                    ../Rover/rover.cpp:734:59: note: candidate expects 1 argument, 6 provided
                    this->ui->label_2);
                    ^
                    In file included from /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/QtConcurrent:16,
                    from ../Rover/rover.cpp:17:
                    /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:82:12: note: candidate: ‘template<class T, class Param1, class Arg1, class Param2, class Arg2> QFuture<T> QtConcurrent::run(T (
                    )(Param1, Param2), const Arg1&, const Arg2&)’
                    QFuture<T> run(T (functionPointer)(Param1, Param2), const Arg1 &arg1, const Arg2 &arg2)
                    ^~~
                    /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:82:12: note: template argument deduction/substitution failed:
                    ../Rover/rover.cpp:734:59: note: candidate expects 2 arguments, 6 provided
                    this->ui->label_2);
                    ^
                    In file included from /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/QtConcurrent:16,
                    from ../Rover/rover.cpp:17:
                    /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:87:12: note: candidate: ‘template<class T, class Param1, class Arg1, class Param2, class Arg2, class Param3, class Arg3> QFuture<T> QtConcurrent::run(T (
                    )(Param1, Param2, Param3), const Arg1&, const Arg2&, const Arg3&)’
                    QFuture<T> run(T (functionPointer)(Param1, Param2, Param3), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3)
                    ^~~
                    /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:87:12: note: template argument deduction/substitution failed:
                    ../Rover/rover.cpp:734:59: note: candidate expects 3 arguments, 6 provided
                    this->ui->label_2);
                    ^
                    In file included from /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/QtConcurrent:16,
                    from ../Rover/rover.cpp:17:
                    /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:92:12: note: candidate: ‘template<class T, class Param1, class Arg1, class Param2, class Arg2, class Param3, class Arg3, class Param4, class Arg4> QFuture<T> QtConcurrent::run(T (
                    )(Param1, Param2, Param3, Param4), const Arg1&, const Arg2&, const Arg3&, const Arg4&)’
                    QFuture<T> run(T (functionPointer)(Param1, Param2, Param3, Param4), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4)
                    ^~~
                    /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:92:12: note: template argument deduction/substitution failed:
                    ../Rover/rover.cpp:734:59: note: candidate expects 4 arguments, 6 provided
                    this->ui->label_2);
                    ^
                    In file included from /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/QtConcurrent:16,
                    from ../Rover/rover.cpp:17:
                    /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:97:12: note: candidate: ‘template<class T, class Param1, class Arg1, class Param2, class Arg2, class Param3, class Arg3, class Param4, class Arg4, class Param5, class Arg5> QFuture<T> QtConcurrent::run(T (
                    )(Param1, Param2, Param3, Param4, Param5), const Arg1&, const Arg2&, const Arg3&, const Arg4&, const Arg5&)’
                    QFuture<T> run(T (*functionPointer)(Param1, Param2, Param3, Param4, Param5), const Arg1 &arg1, const Arg2 &arg2, const Arg3 &arg3, const Arg4 &arg4, const Arg5 &arg5)
                    ^~~
                    /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:97:12: note: template argument deduction/substitution failed:
                    ../Rover/rover.cpp:734:59: note: candidate expects 5 arguments, 6 provided
                    this->ui->label_2);
                    ^
                    In file included from /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/QtConcurrent:16,
                    from ../Rover/rover.cpp:17:
                    /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:105:6: note: candidate: ‘template<class Functor> typename std::enable_if<(! QtPrivate::HasResultType<MapFunctor>::Value), QFuture<decltype (functor())> >::type QtConcurrent::run(Functor)’
                    auto run(Functor functor) -> typename std::enable_if<!QtPrivate::HasResultType<Functor>::Value, QFuture<decltype(functor())>>::type
                    ^~~
                    /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/qtconcurrentrun.h:105:6: note: template argument deduction/substitution failed:
                    ../Rover/rover.cpp:734:59: note: candidate expects 1 argument, 7 provided
                    this->ui->label_2);
                    ^
                    In file included from /usr/include/arm-linux-gnueabihf/qt5/QtConcurrent/QtConcurrent:16,
                    from ../Rover/rover.cpp:17:

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12

                    @najlou said in Passing Arguments to the Function:

                    ../Rover/rover.cpp:734:59: note: candidate expects 5 arguments, 6 provided

                    Yes, it looks like you can't pass more than 5 parameters. If you really need more than 5 parameters you can define a struct where you put all these parameters and then pass this struct as parameter.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by JonB
                      #13

                      @jsulm
                      I note from https://code.woboq.org/qt5/qtbase/src/concurrent/qtconcurrentrun.h.html that there are explicit template definitions going up to 5 parameters. I don't know (can't figure) what happens if you pass 6 or more parameters?

                      @najlou
                      To prove, try the following. Don't try to run the code, it's just to see whether or not it gets through the compiler!

                      QFuture<void> future = QtConcurrent::run(hand,
                      1,
                      2,
                      3,
                      4,
                      5);
                      

                      That compiles, right?
                      Now try:

                      QFuture<void> future = QtConcurrent::run(hand,
                      1,
                      2,
                      3,
                      4,
                      5,
                      6,
                      7);
                      

                      What about this one?

                      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