[英]Qt5: QTextEdit to (LPVOID lpBuffer, DWORD dwBytesToWrite)
I have a GUI with textDataToSend
QTextEdit field and I want to use the data entered in a fWrite
function which accepts (LPVOID lpBuffer, DWORD dwBytesToWrite)
arguments. 我有一个带有
textDataToSend
QTextEdit字段的GUI,我想使用在fWrite
函数中输入的数据,该函数接受(LPVOID lpBuffer, DWORD dwBytesToWrite)
参数。
For now I use: 现在,我使用:
dataToSend[0] = ui->textDataToSend->toPlainText().toUInt(&bStatus,16);
sendData(dataToSend,1);
where sendData
is like: sendData
是这样的:
DWORD sendData(char* txBuffer, unsigned long txBufferSize) {
int status;
status = fWrite(handle, txBuffer, txBufferSize);
return status;
}
With that I am able to send one byte. 这样我就可以发送一个字节。
The data I would like to use are hex strings with variable length (like "aa0011", "1122334455", ...). 我要使用的数据是长度可变的十六进制字符串(例如“ aa0011”,“ 1122334455”,...)。 I'm totally unexperienced, could you please suggest some good, proper, more clever way to do that?
我完全没有经验,可以请您提出一些好的,适当的,更聪明的方法来做到这一点吗?
First get the QString
out of the Text edit 首先从文本编辑器中获取
QString
QString textEditString = ui->textDataToSend->toPlainText();
When you have QString
in your hand, you can get both "buffer" and "size of the buffer" as shown below. 当您手里拿着
QString
时,可以同时获得“缓冲区”和“缓冲区大小”,如下所示。
//First get the byte array from the string
QByteArray bArray = textEditString.toLatin1();
//Get the size of the string in bytes
int length = bArray.size();
//Get the string buffer
char *tBuffer = bArray.data();
Now pass these values to your send data 现在将这些值传递到您的发送数据
sendData(tBuffer, length);
Any how LPVOID
is nothing but a Void pointer. LPVOID
任何方式都不过是Void指针。 fWrite
should be able to take tBuffer
with out any problem. fWrite
应该能够tBuffer
地使用tBuffer
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.