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. sending data over serial port
Forum Updated to NodeBB v4.3 + New Features

sending data over serial port

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.2k Views 2 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
    vidisha
    wrote on last edited by
    #1

    hi....i want to send data over serial port to microcontroller....below is my code and im getting errors...so plz can anyone help
    void MainWindow::on_btStatus_released() {
    if ( m_serialPort->isOpen()) {
    AddStatus("Comport open. ");
    } else {
    AddStatus("Comport not open. ");
    }
    QStringList text = "a";
    m_serialPort->write(text.toStdString().c_str());

    }

    Errors:

    1. error: C2440: 'initializing' : cannot convert from 'const char [2]' to 'QStringList'
      Constructor for class 'QStringList' is declared 'explicit'
    2. error: C2039: 'toStdString' : is not a member of 'QStringList'
      3)error: C2228: left of '.c_str' must have class/struct/union
    jsulmJ 1 Reply Last reply
    0
    • V vidisha

      hi....i want to send data over serial port to microcontroller....below is my code and im getting errors...so plz can anyone help
      void MainWindow::on_btStatus_released() {
      if ( m_serialPort->isOpen()) {
      AddStatus("Comport open. ");
      } else {
      AddStatus("Comport not open. ");
      }
      QStringList text = "a";
      m_serialPort->write(text.toStdString().c_str());

      }

      Errors:

      1. error: C2440: 'initializing' : cannot convert from 'const char [2]' to 'QStringList'
        Constructor for class 'QStringList' is declared 'explicit'
      2. error: C2039: 'toStdString' : is not a member of 'QStringList'
        3)error: C2228: left of '.c_str' must have class/struct/union
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @vidisha

      1. QStringList is a list of strings not a string. You should do QString text = ...
      2. When you fixed 1 then 2 will work

      https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        Hi,

        Error 1: you are trying to assign a string in a QStringList, did you want QString ?
        Error 2: Like written QStringList doesn't have such a method but QString does.
        Error 3: Comes from error 2, you are trying to call a function over a result you don't have.

        Note that QSerialPort::write has an overload that takes a QByteArray so it's useless to do all these conversions

        QByteArray data("a");
        m_serialPort->write(data);
        

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

        V 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          Error 1: you are trying to assign a string in a QStringList, did you want QString ?
          Error 2: Like written QStringList doesn't have such a method but QString does.
          Error 3: Comes from error 2, you are trying to call a function over a result you don't have.

          Note that QSerialPort::write has an overload that takes a QByteArray so it's useless to do all these conversions

          QByteArray data("a");
          m_serialPort->write(data);
          
          V Offline
          V Offline
          vidisha
          wrote on last edited by
          #4
          This post is deleted!
          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