QSerialPort Qchar + QByteArray

  • Hello every one! I develop some application to write/read data from COM-port. I get data from lineEdit and send it to port like:


    all work fine, but i need to add some char to start and and line like:


    but i get and error... Please help, how i can convert Qchar to QByteArray. Thanks!

  • Moderators


    Hi and welcome to devnet

    This has nothing to do with QSerialPort. WriteToPort is not a routine of QSerialPort. It boils down to a pure QByteArray issue.

    If I am not mistaken this may work:


    My guess is that you do not have a routine fitting the outcome. You should see in the error protocol of your compile run.

  • get the error:
    mainwindow.cpp:35: error: ambiguous overload for 'operator+' (operand types are 'QChar' and 'QByteArray')

  • Moderators


    What is the prototyp for WriteToPort look like?

    QString tmp (QChar(253)+ui->lineEdit_2->text()+QChar(254));

    Not sure why you are using toLocal8bit. With standard string the statement above shall work, so it should be with QString, I guess.

  •   QString s="string text";
      QByteArray b= s.toUtf8()+QByteArray("tekst")+QByteArray::fromHex("1310");

  • Thanks for everyone . Create like:

    QByteArray data;

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.