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. Not able to read data from QSerialPort

Not able to read data from QSerialPort

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 604 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.
  • V Offline
    V Offline
    VinQtUser
    wrote on last edited by
    #1

    When I write any data to the Serial Port character wise, I'm getting the expected response from my hardware. But when I send strings, I'm not able to read. I initialized my data using QByteArray but when I use QString, I'm not able to get the expected response. The code is same as Terminal Program for Qt 5.5. I'm coding in C++ on Windows platform.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi and welcome
      <<But when I send strings, I'm not able to read.
      How not able to read?
      Do yo u get nothing or only some?

      If you data contains zero, it wont work with QStrings as it will be broken up.

      Have you tried
      QString string("I LOVE HARDWARE");
      QByteArray array (string.toStdString().c_str());
      serial->write(array);

      1 Reply Last reply
      1
      • V Offline
        V Offline
        VinQtUser
        wrote on last edited by
        #3

        Thanks for the tip. 'c_str' did the trick. Did not know about this.

        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