Want to write the two array string in arduino?
-
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.
-
@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();
-
@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?
-
This post is deleted!
-
@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());
-
Hi,
@jsulm
char* mohit = output.toStdString().c_str();
theremohit
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.
-
@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?
-
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).
-
@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/9