Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Want to write the two array string in arduino?

Want to write the two array string in arduino?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
9 Posts 4 Posters 1.7k 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.
  • M Offline
    M Offline
    Mohit Tripathi
    wrote on last edited by Mohit Tripathi
    #1
    void Dialog::on_pushButton_clicked()
    {
        QString output[10];
        output[0] = ui->lineEdit->text();
        output[1] = ui->lineEdit_2->text();
        QString *mohit = &output;
        if(arduino->isWritable())
        {
            for(int i=0;i<2;i++)
            {
              arduino->write(mohit[i].toStdString().c_str());
            }
             arduino->flush();
             arduino->waitForBytesWritten(100);
             qDebug()<<mohit;
        }
    }
    

    Error is "Can not convert QString(*)[3] to QString in initialization".
    Can I know why we can not convert QString to QC char?
    Then how can I write the two array ouput[0] and output[1] in arduino?

    Note: I can write the string in arduino but not multiple arrays.

    jsulmJ 1 Reply Last reply
    0
    • M Mohit Tripathi
      void Dialog::on_pushButton_clicked()
      {
          QString output[10];
          output[0] = ui->lineEdit->text();
          output[1] = ui->lineEdit_2->text();
          QString *mohit = &output;
          if(arduino->isWritable())
          {
              for(int i=0;i<2;i++)
              {
                arduino->write(mohit[i].toStdString().c_str());
              }
               arduino->flush();
               arduino->waitForBytesWritten(100);
               qDebug()<<mohit;
          }
      }
      

      Error is "Can not convert QString(*)[3] to QString in initialization".
      Can I know why we can not convert QString to QC char?
      Then how can I write the two array ouput[0] and output[1] in arduino?

      Note: I can write the string in arduino but not multiple arrays.

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @Mohit-Tripathi said in Want to write the two array string in arduino?:

      Can I know why we can not convert QString to QC char?

      Why do you think you can't?
      Your code is wrong in several places.
      This can't work as you can't assign a string to a char:

      output[0] = ui->lineEdit->text();
      

      This line is wrong too:

      arduino->write(mohit[i].toStdString().c_str());
      

      Pleas read documentation http://doc.qt.io/qt-5/qstring.html#operator-5b-5d
      mohit[i] returns a char not a string!

      Do you want to concatenate ui->lineEdit->text() and ui->lineEdit_2->text()? Then simply do

      QString output = ui->lineEdit->text() + ui->lineEdit_2->text();
      char* mohit = output.toStdString().c_str();
      
      M 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Mohit-Tripathi said in Want to write the two array string in arduino?:

        Can I know why we can not convert QString to QC char?

        Why do you think you can't?
        Your code is wrong in several places.
        This can't work as you can't assign a string to a char:

        output[0] = ui->lineEdit->text();
        

        This line is wrong too:

        arduino->write(mohit[i].toStdString().c_str());
        

        Pleas read documentation http://doc.qt.io/qt-5/qstring.html#operator-5b-5d
        mohit[i] returns a char not a string!

        Do you want to concatenate ui->lineEdit->text() and ui->lineEdit_2->text()? Then simply do

        QString output = ui->lineEdit->text() + ui->lineEdit_2->text();
        char* mohit = output.toStdString().c_str();
        
        M Offline
        M Offline
        Mohit Tripathi
        wrote on last edited by
        #3

        @jsulm I don't want to concatenate. I want to write the data in two different memory locations in arduino. That's why I am using pointer to array. But, I am getting error. Is this possible in Qt?

        jsulmJ 2 Replies Last reply
        0
        • M Mohit Tripathi

          @jsulm I don't want to concatenate. I want to write the data in two different memory locations in arduino. That's why I am using pointer to array. But, I am getting error. Is this possible in Qt?

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • M Mohit Tripathi

            @jsulm I don't want to concatenate. I want to write the data in two different memory locations in arduino. That's why I am using pointer to array. But, I am getting error. Is this possible in Qt?

            jsulmJ Online
            jsulmJ Online
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Mohit-Tripathi I misunderstood your code first.
            Why do you have this mohit variable?
            This should work:

            if(arduino->isWritable())
            {
                for(int i=0;i<2;i++)
                {
                  arduino->write(output[i].toStdString().c_str());
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              @jsulm char* mohit = output.toStdString().c_str(); there mohit will point to a memory location that's likely invalid since it's taken from a temporary.

              @Mohit-Tripathi I think there's an understanding problem here. What your desktop application does and what your Arduino board does are two very different things. If you want to store your data in two different memory segment on your Arduino then that's something you have to program on your Arduino directly. Your desktop application here merely talks to your board through a serial port. You can't just dump stuff on the serial port and expect it to do what you want unless you properly programmed the Arduino to do it. You likely need to first establish a communication protocol between the two to ensure that everything runs as expected.

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

              M 1 Reply Last reply
              2
              • SGaistS SGaist

                Hi,

                @jsulm char* mohit = output.toStdString().c_str(); there mohit will point to a memory location that's likely invalid since it's taken from a temporary.

                @Mohit-Tripathi I think there's an understanding problem here. What your desktop application does and what your Arduino board does are two very different things. If you want to store your data in two different memory segment on your Arduino then that's something you have to program on your Arduino directly. Your desktop application here merely talks to your board through a serial port. You can't just dump stuff on the serial port and expect it to do what you want unless you properly programmed the Arduino to do it. You likely need to first establish a communication protocol between the two to ensure that everything runs as expected.

                M Offline
                M Offline
                Mohit Tripathi
                wrote on last edited by
                #7

                @SGaist It means that firstly I have to do the arduino coding then after that application will work accordingly. There is no need to define the pointer to array in Qt for define the different memory location in arduino. Am I right?

                jsulmJ 1 Reply Last reply
                0
                • aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Mohit-Tripathi

                  You need to define a protocol that your desktop app and your arduino app speak and wich defines how commands are interpreted by both sides.

                  This is the very basic talk of every communication between devices.

                  You can either invent your own protocol or stick with something ready (there are plenty of protocols out there).

                  Qt has to stay free or it will die.

                  1 Reply Last reply
                  0
                  • M Mohit Tripathi

                    @SGaist It means that firstly I have to do the arduino coding then after that application will work accordingly. There is no need to define the pointer to array in Qt for define the different memory location in arduino. Am I right?

                    jsulmJ Online
                    jsulmJ Online
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Mohit-Tripathi said in Want to write the two array string in arduino?:

                    There is no need to define the pointer to array in Qt for define the different memory location in arduino. Am I right?

                    Yes. How can a pointer in your Qt app have any influence on where the data is stored on Arduino?! Your Arduino (the receiving app there) has no idea who is sending the data and what pointers are used on the other side.

                    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