Results 1 to 13 of 13

Thread: Get hex from Qlineedit and send to serial port

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Qt products
    Qt5
    Platforms
    MacOS X
    Thanks
    13
    Thanked 153 Times in 150 Posts

    Default Re: Get hex from Qlineedit and send to serial port

    You don't need to specify the size of the byte array if you use QByteArray, that was my whole point. Here is your code using QByteArray and proper for loop bounds:

    Qt Code:
    1. QString input = ui->data->text();
    2. QStringList list1 = input.split(",");
    3. int size = list1.size();
    4. QByteArray senddata;
    5. for (int i=0; i < size; i++){
    6. QString ran = list1 [i];
    7. bool ok;
    8. senddata[i]=ran.toInt(&ok,16);
    9. }
    10.  
    11. serial->write(senddata.constData(), senddata.length());
    To copy to clipboard, switch view to plain text mode 
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  2. The following user says thank you to jefftee for this useful post:

    hovuquocan1997 (29th July 2015)

  3. #2
    Join Date
    Jul 2015
    Posts
    18
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    11

    Default Re: Get hex from Qlineedit and send to serial port

    Thank you very much, that solved everything! Thanks for helping me so much, I really appreciate it!

Similar Threads

  1. Convert int to hex and add to char array to send to serial port
    By hovuquocan1997 in forum Qt Programming
    Replies: 2
    Last Post: 15th July 2015, 17:13
  2. Serial read misses to read data from the serial port
    By mania in forum Qt for Embedded and Mobile
    Replies: 11
    Last Post: 18th August 2014, 08:49
  3. Replies: 1
    Last Post: 13th March 2013, 08:44
  4. Replies: 5
    Last Post: 27th May 2011, 09:38
  5. send binary file over serial port with QSerialDevice
    By ilpaso in forum Qt Programming
    Replies: 30
    Last Post: 13th December 2010, 12:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.