Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Error: no viable overloaded '='
Forum Updated to NodeBB v4.3 + New Features

Error: no viable overloaded '='

Scheduled Pinned Locked Moved Solved Mobile and Embedded
9 Posts 4 Posters 8.4k 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.
  • M Offline
    M Offline
    Mohit Tripathi
    wrote on 15 Nov 2019, 11:20 last edited by
    #1

    Hi,

    I am getting the error while assigning a QString intoan array. But, I am getting the error for x "Error: no viable overloaded '='". Why am I getting this while assigning string to an element of array?

    int data = ui->lineEdit->text().toInt();
    int cal =  static_cast<int>(ceil(((data)*3)/2));
        QString hex = QString::number( cal, 16 ).toUpper();
        qDebug()<<"Calculated value:"<<hex;
    
        QString m = "0x";
        QString n = hex;
    
        m.append(n);
        qDebug()<<"append:"<<m;
       sendPacket[0]=m;
    
    J 1 Reply Last reply 15 Nov 2019, 11:27
    0
    • M Mohit Tripathi
      15 Nov 2019, 11:20

      Hi,

      I am getting the error while assigning a QString intoan array. But, I am getting the error for x "Error: no viable overloaded '='". Why am I getting this while assigning string to an element of array?

      int data = ui->lineEdit->text().toInt();
      int cal =  static_cast<int>(ceil(((data)*3)/2));
          QString hex = QString::number( cal, 16 ).toUpper();
          qDebug()<<"Calculated value:"<<hex;
      
          QString m = "0x";
          QString n = hex;
      
          m.append(n);
          qDebug()<<"append:"<<m;
         sendPacket[0]=m;
      
      J Offline
      J Offline
      JonB
      wrote on 15 Nov 2019, 11:27 last edited by
      #2

      @Mohit-Tripathi
      What array? Is the error on sendPacket[0]=m;, why not tell us? Assuming it is, how can we answer if we don't know the declaration of sendPacket?

      1 Reply Last reply
      2
      • M Offline
        M Offline
        Mohit Tripathi
        wrote on 15 Nov 2019, 11:37 last edited by Mohit Tripathi
        #3

        Hi,

        @JonB Yes, the error is on sendPacket[0]=m. I have declared in my code but still i am getting the error.
        Declaration is " QString sendPacket".

        Thanks

        J 1 Reply Last reply 15 Nov 2019, 11:52
        0
        • M Mohit Tripathi
          15 Nov 2019, 11:37

          Hi,

          @JonB Yes, the error is on sendPacket[0]=m. I have declared in my code but still i am getting the error.
          Declaration is " QString sendPacket".

          Thanks

          J Offline
          J Offline
          JonB
          wrote on 15 Nov 2019, 11:52 last edited by
          #4

          @Mohit-Tripathi
          If your actual declaration is

          QString sendPacket

          then it is not an array (of QStrings, I mean), is it, so why do you say it is an array or index it like an array? You tell me what type sendPacket[0] is?

          M 1 Reply Last reply 18 Nov 2019, 06:31
          4
          • J JonB
            15 Nov 2019, 11:52

            @Mohit-Tripathi
            If your actual declaration is

            QString sendPacket

            then it is not an array (of QStrings, I mean), is it, so why do you say it is an array or index it like an array? You tell me what type sendPacket[0] is?

            M Offline
            M Offline
            Mohit Tripathi
            wrote on 18 Nov 2019, 06:31 last edited by
            #5

            @JonB
            Hi,
            It is QByteArray sendPacket; not QString sendPacket.

            J J 2 Replies Last reply 18 Nov 2019, 06:33
            0
            • M Mohit Tripathi
              18 Nov 2019, 06:31

              @JonB
              Hi,
              It is QByteArray sendPacket; not QString sendPacket.

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 18 Nov 2019, 06:33 last edited by
              #6

              @Mohit-Tripathi You are trying to assign a QString to a char: https://doc.qt.io/qt-5/qbytearray.html#operator-5b-5d-1
              This can't work...

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

              1 Reply Last reply
              4
              • M Mohit Tripathi
                18 Nov 2019, 06:31

                @JonB
                Hi,
                It is QByteArray sendPacket; not QString sendPacket.

                J Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 18 Nov 2019, 06:34 last edited by
                #7

                @Mohit-Tripathi said in Error: no viable overloaded '=':

                @JonB
                Hi,
                It is QByteArray sendPacket; not QString sendPacket.

                And there's the issue isn't it, QByteArray != QString

                What exactly do you want? A "List" of QStrings, or do you want the content of your QString as a QByteArray?


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                M 1 Reply Last reply 18 Nov 2019, 06:46
                2
                • J J.Hilk
                  18 Nov 2019, 06:34

                  @Mohit-Tripathi said in Error: no viable overloaded '=':

                  @JonB
                  Hi,
                  It is QByteArray sendPacket; not QString sendPacket.

                  And there's the issue isn't it, QByteArray != QString

                  What exactly do you want? A "List" of QStrings, or do you want the content of your QString as a QByteArray?

                  M Offline
                  M Offline
                  Mohit Tripathi
                  wrote on 18 Nov 2019, 06:46 last edited by Mohit Tripathi
                  #8

                  @J-Hilk
                  Hi,
                  I want to store the 16 bit value in a string. I am able to store the 8 bit but not 16 bit. I am able to this:
                  QByteArray ba;
                  ba.resize(5);
                  ba[0] = 0x3c;

                  But, not like this:
                  QByteArray ba;
                  ba.resize(5);
                  ba[0] = 0x60c1;

                  This is exactly what I am trying to do. After that, I am able to transmit the 8 bit data but not 16 bit.

                  void transmit(QSerialPort & port, const QByteArray & data) {
                      port.write(data);
                      port.flush();
                      qDebug() << "\nWrote" << data.size() << ":" << data.toHex().constData();
                      chkError(port);
                  }
                  
                  J 1 Reply Last reply 18 Nov 2019, 06:57
                  0
                  • M Mohit Tripathi
                    18 Nov 2019, 06:46

                    @J-Hilk
                    Hi,
                    I want to store the 16 bit value in a string. I am able to store the 8 bit but not 16 bit. I am able to this:
                    QByteArray ba;
                    ba.resize(5);
                    ba[0] = 0x3c;

                    But, not like this:
                    QByteArray ba;
                    ba.resize(5);
                    ba[0] = 0x60c1;

                    This is exactly what I am trying to do. After that, I am able to transmit the 8 bit data but not 16 bit.

                    void transmit(QSerialPort & port, const QByteArray & data) {
                        port.write(data);
                        port.flush();
                        qDebug() << "\nWrote" << data.size() << ":" << data.toHex().constData();
                        chkError(port);
                    }
                    
                    J Offline
                    J Offline
                    J.Hilk
                    Moderators
                    wrote on 18 Nov 2019, 06:57 last edited by J.Hilk
                    #9

                    @Mohit-Tripathi that is correct,

                    Like @jsulm said, QByteArray only accepts char as it lowest form.

                    You have to assign the 1st index the high byte and the 2nd index (of the byte array) the Low byte (or flipped, depending on endianness )

                    That said, your previous int to hex string conversion is unneeded and probably wrong too.


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    1 Reply Last reply
                    3

                    3/9

                    15 Nov 2019, 11:37

                    6 unread
                    • Login

                    • Login or register to search.
                    3 out of 9
                    • First post
                      3/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved