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 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;
    
    JonBJ 1 Reply Last reply
    0
    • M Mohit Tripathi

      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;
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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 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

        JonBJ 1 Reply Last reply
        0
        • M Mohit Tripathi

          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

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on 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
          4
          • JonBJ JonB

            @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 last edited by
            #5

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

            jsulmJ J.HilkJ 2 Replies Last reply
            0
            • M Mohit Tripathi

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

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on 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

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

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on 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
                2
                • J.HilkJ J.Hilk

                  @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 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.HilkJ 1 Reply Last reply
                  0
                  • M Mohit Tripathi

                    @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.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on 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

                    • Login

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