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. invalid conversion error in signal connection
Forum Updated to NodeBB v4.3 + New Features

invalid conversion error in signal connection

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 2 Posters 1.2k 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.
  • A Offline
    A Offline
    agmar
    wrote on last edited by
    #1

    hi, i am not sure what do do with this, i have not been able to find information on what this means or why it happens...

    9d17c3a9-71d9-4472-9ee0-f9342f22b659-image.png
    6cb5f6b8-2126-4a82-b4a9-1b9633e6e276-image.png

    66ed268b-d605-4054-8640-e01c383ac7c9-image.png

    error: invalid conversion from ‘uint8_t’ {aka ‘unsigned char’} to ‘uint8_t*’ {aka ‘unsigned char*’} [-fpermissive]
    64 | connect(delayer, &QTimer::timeout, this, &MainWindow::on_TGetButton_clicked(message_arr[0]));
    | ~^
    | |
    | uint8_t {aka unsigned char}
    ~~~~~~~^~

    jsulmJ 1 Reply Last reply
    0
    • A agmar

      @jsulm no idea how to address that... perhaps when i read more about lambdas, i can, but until then, i am in the dark

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

      @agmar You need to understand what connect actually does and what not. It does NOT pass any parameters to the slot (what you're trying to do in your code). It just establishes the connection between signal and slot. Parameter is passed from signal to slot when the signal is emitted. If you want to pass some parameters to slot which are not passed from the signal (like in your case) you need to use a lambda as slot.

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

      A 2 Replies Last reply
      1
      • A agmar

        hi, i am not sure what do do with this, i have not been able to find information on what this means or why it happens...

        9d17c3a9-71d9-4472-9ee0-f9342f22b659-image.png
        6cb5f6b8-2126-4a82-b4a9-1b9633e6e276-image.png

        66ed268b-d605-4054-8640-e01c383ac7c9-image.png

        error: invalid conversion from ‘uint8_t’ {aka ‘unsigned char’} to ‘uint8_t*’ {aka ‘unsigned char*’} [-fpermissive]
        64 | connect(delayer, &QTimer::timeout, this, &MainWindow::on_TGetButton_clicked(message_arr[0]));
        | ~^
        | |
        | uint8_t {aka unsigned char}
        ~~~~~~~^~

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

        @agmar Please post code as text!
        This code is not valid C++ code. You can't pass data to the slot when you connect the slot to signal! Parameters are passed when signal is emitted. If you want to pass message_arr[0] you should use a lambda as slot. Also your slot seems to take a pointer but you're passing by value.

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

        A 1 Reply Last reply
        1
        • jsulmJ jsulm

          @agmar Please post code as text!
          This code is not valid C++ code. You can't pass data to the slot when you connect the slot to signal! Parameters are passed when signal is emitted. If you want to pass message_arr[0] you should use a lambda as slot. Also your slot seems to take a pointer but you're passing by value.

          A Offline
          A Offline
          agmar
          wrote on last edited by
          #3

          @jsulm

          Whats a lambda? after changing the pointer into an uint8_t , this is the new error:

          MainWindow::on_upButton_clicked(uint8_t)’:
          error: invalid types ‘uint8_t {aka unsigned char}[int]’ for array subscript
          147 | tx_buffer[0] = 1;
          | ^

          jsulmJ 1 Reply Last reply
          0
          • A agmar

            @jsulm

            Whats a lambda? after changing the pointer into an uint8_t , this is the new error:

            MainWindow::on_upButton_clicked(uint8_t)’:
            error: invalid types ‘uint8_t {aka unsigned char}[int]’ for array subscript
            147 | tx_buffer[0] = 1;
            | ^

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

            @agmar said in invalid conversion error in signal connection:

            Whats a lambda?

            https://en.cppreference.com/w/cpp/language/lambda

            Did you also address "You can't pass data to the slot when you connect the slot to signal!"?

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

            A 1 Reply Last reply
            0
            • jsulmJ jsulm

              @agmar said in invalid conversion error in signal connection:

              Whats a lambda?

              https://en.cppreference.com/w/cpp/language/lambda

              Did you also address "You can't pass data to the slot when you connect the slot to signal!"?

              A Offline
              A Offline
              agmar
              wrote on last edited by
              #5

              @jsulm no idea how to address that... perhaps when i read more about lambdas, i can, but until then, i am in the dark

              jsulmJ 1 Reply Last reply
              0
              • A agmar

                @jsulm no idea how to address that... perhaps when i read more about lambdas, i can, but until then, i am in the dark

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

                @agmar You need to understand what connect actually does and what not. It does NOT pass any parameters to the slot (what you're trying to do in your code). It just establishes the connection between signal and slot. Parameter is passed from signal to slot when the signal is emitted. If you want to pass some parameters to slot which are not passed from the signal (like in your case) you need to use a lambda as slot.

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

                A 2 Replies Last reply
                1
                • jsulmJ jsulm

                  @agmar You need to understand what connect actually does and what not. It does NOT pass any parameters to the slot (what you're trying to do in your code). It just establishes the connection between signal and slot. Parameter is passed from signal to slot when the signal is emitted. If you want to pass some parameters to slot which are not passed from the signal (like in your case) you need to use a lambda as slot.

                  A Offline
                  A Offline
                  agmar
                  wrote on last edited by
                  #7

                  @jsulm thank you, i will follow the link you gave!

                  1 Reply Last reply
                  0
                  • A agmar has marked this topic as solved on
                  • jsulmJ jsulm

                    @agmar You need to understand what connect actually does and what not. It does NOT pass any parameters to the slot (what you're trying to do in your code). It just establishes the connection between signal and slot. Parameter is passed from signal to slot when the signal is emitted. If you want to pass some parameters to slot which are not passed from the signal (like in your case) you need to use a lambda as slot.

                    A Offline
                    A Offline
                    agmar
                    wrote on last edited by
                    #8

                    @jsulm said in invalid conversion error in signal connection:

                    @agmar You need to understand what connect actually does and what not. It does NOT pass any parameters to the slot (what you're trying to do in your code). It just establishes the connection between signal and slot. Parameter is passed from signal to slot when the signal is emitted. If you want to pass some parameters to slot which are not passed from the signal (like in your case) you need to use a lambda as slot.

                    hm, well , i seem to understand how a lambda works now , thank you for telling me about them :) however, i still cant get the connection to work, the function with an added lambda looked like this :
                    connect(delayer, &QTimer::timeout, this, [ message_arr[0] ](uint8_t tx_buffer){&MainWindow::on_TGetButton_clicked;});

                    but it just gives an error for " Expected',' or '}' in lambda capture list not sure what that means, but it would be nice if there would be a way to just write the variable name into the function call with the lambda without changing the contents of the function, because i would still have to go into the function and internally change the definition from message_arr[0]=tx_buffer to newVariable = tx_buffer

                    Is this something that is possible to do?

                    jsulmJ 1 Reply Last reply
                    0
                    • A agmar

                      @jsulm said in invalid conversion error in signal connection:

                      @agmar You need to understand what connect actually does and what not. It does NOT pass any parameters to the slot (what you're trying to do in your code). It just establishes the connection between signal and slot. Parameter is passed from signal to slot when the signal is emitted. If you want to pass some parameters to slot which are not passed from the signal (like in your case) you need to use a lambda as slot.

                      hm, well , i seem to understand how a lambda works now , thank you for telling me about them :) however, i still cant get the connection to work, the function with an added lambda looked like this :
                      connect(delayer, &QTimer::timeout, this, [ message_arr[0] ](uint8_t tx_buffer){&MainWindow::on_TGetButton_clicked;});

                      but it just gives an error for " Expected',' or '}' in lambda capture list not sure what that means, but it would be nice if there would be a way to just write the variable name into the function call with the lambda without changing the contents of the function, because i would still have to go into the function and internally change the definition from message_arr[0]=tx_buffer to newVariable = tx_buffer

                      Is this something that is possible to do?

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

                      @agmar said in invalid conversion error in signal connection:

                      connect(delayer, &QTimer::timeout, this, [ message_arr[0] ](uint8_t tx_buffer){&MainWindow::on_TGetButton_clicked;});

                      QTimer::timeout has no parameter of type uint8_t, so why does your lambda have such a parameter? Also, you can't capture something like message_arr[0] in a lambda, you can capture message_arr.

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

                      A 1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @agmar said in invalid conversion error in signal connection:

                        connect(delayer, &QTimer::timeout, this, [ message_arr[0] ](uint8_t tx_buffer){&MainWindow::on_TGetButton_clicked;});

                        QTimer::timeout has no parameter of type uint8_t, so why does your lambda have such a parameter? Also, you can't capture something like message_arr[0] in a lambda, you can capture message_arr.

                        A Offline
                        A Offline
                        agmar
                        wrote on last edited by
                        #10

                        @jsulm ah... i see what you mean, the code now compiles, i just didnt need any parameter emitted by QTimer::timetout.

                        Is it possible to have the captured parameters renamed to something else? i wanted to use local variables, but if i have to specify message_arr , as it was captured, it will not work out, i think...
                        maybe something like when we call a regular function with input parameters?

                        jsulmJ 1 Reply Last reply
                        0
                        • A agmar

                          @jsulm ah... i see what you mean, the code now compiles, i just didnt need any parameter emitted by QTimer::timetout.

                          Is it possible to have the captured parameters renamed to something else? i wanted to use local variables, but if i have to specify message_arr , as it was captured, it will not work out, i think...
                          maybe something like when we call a regular function with input parameters?

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

                          @agmar said in invalid conversion error in signal connection:

                          it will not work out, i think...

                          it will even if message_arr is a local variable

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

                          A 1 Reply Last reply
                          0
                          • jsulmJ jsulm

                            @agmar said in invalid conversion error in signal connection:

                            it will not work out, i think...

                            it will even if message_arr is a local variable

                            A Offline
                            A Offline
                            agmar
                            wrote on last edited by
                            #12

                            @jsulm what in the case of global variables tho?
                            is it not better to make the functions more reusable by converting the function inputs into locals inside the function? since message_arr is global, having it inside the other functions will make the code less portable and changes will be have to be made everytime a parameter name is changed, maybe that is ok if there is no other option, but surely there should be

                            jsulmJ 1 Reply Last reply
                            0
                            • A agmar

                              @jsulm what in the case of global variables tho?
                              is it not better to make the functions more reusable by converting the function inputs into locals inside the function? since message_arr is global, having it inside the other functions will make the code less portable and changes will be have to be made everytime a parameter name is changed, maybe that is ok if there is no other option, but surely there should be

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

                              @agmar said in invalid conversion error in signal connection:

                              is it not better to make the functions more reusable by converting the function inputs into locals inside the function?

                              If a parameter of a function can be a local variable then the question is: why was it a parameter at all? Local variables and function parameters are different concepts. So, if message_arr is "global" (global variables are bad design btw.) then why do you want to pass it to the slot/lambda as parameter?
                              But what I actually wanted to say is: you can also capture local variables in a lambda.

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

                              A 1 Reply Last reply
                              1
                              • jsulmJ jsulm

                                @agmar said in invalid conversion error in signal connection:

                                is it not better to make the functions more reusable by converting the function inputs into locals inside the function?

                                If a parameter of a function can be a local variable then the question is: why was it a parameter at all? Local variables and function parameters are different concepts. So, if message_arr is "global" (global variables are bad design btw.) then why do you want to pass it to the slot/lambda as parameter?
                                But what I actually wanted to say is: you can also capture local variables in a lambda.

                                A Offline
                                A Offline
                                agmar
                                wrote on last edited by
                                #14

                                @jsulm said in invalid conversion error in signal connection:

                                So, if message_arr is "global" (global variables are bad design btw.) then why do you want to pass it to the slot/lambda as parameter?

                                yes , that is what i mean aswell, i prefer to avoid global variables, but message_arr will require only a few of the bytes to be changed for every message, so it makes sense to have it as global, so every function can edit it slightly instead of redefining 10 bytes of data, since that in the end will have to be defined in every individual function i use if i dont make it global, so it seems logical to use a global for message_arr

                                That aside , i still want to use local variables inside every function, so for example , when on_TGoButton_Clicked is called, i want the message_arr to appear as tx_buffer because it will need minor modifications and it will be used as a parameter for functions inside on_TGoButton_Clicked , here's an example

                                void MainWindow::on_TGoButton_clicked(uint8_t tx_buffer)
                                {

                                MainWindow::writeSerial(tx_buffer);
                                lastPress = "TGo";
                                
                                printOut(tx_buffer);
                                

                                }

                                i would really prefer to have tx_buffer instead of punching in message_arr directly, which, like is said is a hassle if i want to change then name of message_arr for example...

                                at this point, i can assume there is no optionto specify the input parameter for as i do in MainWindow::writeSerial(tx_buffer);?

                                jsulmJ 1 Reply Last reply
                                0
                                • A agmar

                                  @jsulm said in invalid conversion error in signal connection:

                                  So, if message_arr is "global" (global variables are bad design btw.) then why do you want to pass it to the slot/lambda as parameter?

                                  yes , that is what i mean aswell, i prefer to avoid global variables, but message_arr will require only a few of the bytes to be changed for every message, so it makes sense to have it as global, so every function can edit it slightly instead of redefining 10 bytes of data, since that in the end will have to be defined in every individual function i use if i dont make it global, so it seems logical to use a global for message_arr

                                  That aside , i still want to use local variables inside every function, so for example , when on_TGoButton_Clicked is called, i want the message_arr to appear as tx_buffer because it will need minor modifications and it will be used as a parameter for functions inside on_TGoButton_Clicked , here's an example

                                  void MainWindow::on_TGoButton_clicked(uint8_t tx_buffer)
                                  {

                                  MainWindow::writeSerial(tx_buffer);
                                  lastPress = "TGo";
                                  
                                  printOut(tx_buffer);
                                  

                                  }

                                  i would really prefer to have tx_buffer instead of punching in message_arr directly, which, like is said is a hassle if i want to change then name of message_arr for example...

                                  at this point, i can assume there is no optionto specify the input parameter for as i do in MainWindow::writeSerial(tx_buffer);?

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

                                  @agmar I don't know your design, so don't know why message_arr needs to be global. I doubt it really has to. It is really bad design if you're changing a global variable in many places in your app. You should rethink the design.

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

                                  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