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. Help with Qt Invalid conversion

Help with Qt Invalid conversion

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.6k 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.
  • H Offline
    H Offline
    houmingc
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • H Offline
        H Offline
        houmingc
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0

          • Login

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