Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Help with Qt Invalid conversion

    General and Desktop
    2
    4
    1370
    Loading More Posts
    • 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.
    • H
      houmingc last edited by

      Error created in below code
      a-invalid conversion from 'unsigned char' to 'const char*'
      b-no matching function for call to 'QSerialPort::write(QString)

      @
      void MainWindow::SendContrast()
      {

              static const char Contrast0[]={0x08,0x11,0x01,0x00,0x00,'\0'};
              static const char Contrast1[]={0x04,0x12,0x84,'\0'};
      
              serial->write(Contrast0);
              serial->write(ui->ContrastCombo->currentText());      //a
              serial->write(ModBusCRC(Contrast0,sizeof(Contrast0)));    //b because ModBusCRC return a const char
              serial->write(Contrast1);
              serial->write(ModBusCRC(Contrast1,sizeof(Contrast1)));
      

      }

      @

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        currentText() returns a QString where write wants a QByteArray so you have to convert it using e.g. toLatin1().

        Where exactly does the other error happen ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • H
          houmingc last edited by

          thanks, i edit the question.
          Understood QLatin1 better now
          http://qt-project.org/doc/qt-4.8/qlatin1string.html

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Then something like:

            @
            char crc = ModBusCRC(Contrast0,sizeof(Contrast0));
            serial->write(&crc, 1);
            @

            should work.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • First post
              Last post