Hello everyone,
I am using Qt Designer to create a GUI for Mini2440 and C++.
But I am not good at C++.
So, in GUI, I have object "Line edit" to receive character for user.
So, this text is defined "Qstring". So, I wanna convert it to 'char' to
send by UART.
So, my code to get text from Line edit:
QString text="";
text=box->text();//box is the name of the object "Line edit"
I cannot use:
char temp[]="";
temp=text.latin1();
My function: write(fd, temp, n_bytes); to send UART.
How can I convert "text" as Qstring above to "temp" as Char.
Thannks in advance.
QT and Mini2440: convert Qstring to Char
This is question not related to this forum!!!Anyway you can use: QString text = "abc"; char *txt = text.toAscii().data(); Marek
Firstly,Iam so sorry because of posting this topic in wrong possition.
Sencondly, Thanks you Open-nandra. But Qt cannot find ".toAscii" although I
included Qcstring.h & Qstring.h.
Some more about my project:
My project uses QtDesigner to create a GUI for Kit Mini2440. It has a Line
edit box to receive texts from user and send them via UART. All project was
built without error and downloaded to the Mini2440 successfully.
But, when I press SEND button to send texts in this box "Line edit", I got
the message "[name of project] was terminated due to application error
(11)".
This is my code to change get text and send them:
I use library "terminos.h" for UART
[code]
QString text="";
text=text_setspeed->text();
//text_setspeed is the name of the Line edit
write(fd,text.latin1(),text.length());
// But if I code like this, it has no error:
QString text="abc";
write(fd,text.latin1(),text.length());
[/code]
Ps: I included my project
Well if it crashes you have something wrong in your code ;). You use qtopia not qt embedded for app development? At least QString has toAscii method: http://doc.qt.nokia.com/latest/qstring.html#toAscii Marek
Iam using Qt Designer by Trolltech.
If I use
"
QString text="";
text=text_setspeed->text();
"
I got error ""[name of project] was terminated due to application error
(11)"
Do you have another way to get text from Line edit?
Thank you so much.
Well I suppose there is no problem with get string from lineedit: Normally QString lineEditText = lineEdit->text(); I think problem is with you sp_write function because you set string liegth to some number which could lead to access memory which not belong to you. Just use that: QString lineEditText = lineEdit->text(); QByteArray send = lineEditText.toAscii(); int len = send.size(); sp.sp_write(send.data(), len); Marek
Thank you very much, Open-nandra. I included qcstring.h, Qstring.h and I used code above. But it couldnot build. The error is: Class Qstring has no member named "toAscii". Sorry if my question was stupid. :D because I've just used Linux embedded for 2 weeks. Again, I sincerely appreciate your enthusiasm. Wish you stay healthy and successful Ps.I include the screen with the error.
OK download qtopia sources and find it out try this: QString lineEditText = lineEdit->text(); int len = send.lineEditText(); sp.sp_write(lineEditText.data(), len); Marek
Iam using Qtopia 2.2.0, But, qstring.h doesnot have function .toAscii or .ascii , it just have .latin1(). Do I have to download the newer version Qtopia? Thank you so much.
Do you read my last comment? There is no toAscii(). QString lineEditText = lineEdit->text(); int len = lineEditText.size(); sp.sp_write(lineEditText.data(), len);
When I use your code, I got an error: Class Qstring has no member named 'size' and some other errors. I attach the image of the error. Thank you so much, Open-nandra.
Hey man, did you ever code? ;) I give you an pointer: you have lineEditText.data() which is char * so why don't you use C strlen instead size() method. I don't find any Qtopia docu to check QString, sorry.
hi coungle, may be the problem is in here:
void MotorForm::stopmotor()
{
//add your code here
//int i;
//i=text1.length();
//QString text="abc";
char txt[]="abc";
//QByteArray temp =text.toAscii();
//char *txt=temp.data();
//text=text_setspeed->text();
//char *txt=text.toAscii().data();
//char data[]="Stop Motor\n\r";
sp.sp_write(txt,10);
}


