Qt 用Windows进程间通信 发送结构体,结构体内容中不能有QString格式吗?
请看源码:
1.发送方:
void Sender::onSendMessage()
{
HWND hwnd = NULL;
LPWSTR path = (LPWSTR)c_strTitle.utf16(); //path = L"SendMessage"
hwnd = ::FindWindowW(NULL,path);
if(::IsWindow(hwnd))
{
struct test
{
QSting tq;
float tf;
int ti;
}tt;
tt.tf=3.14;
tt.ti=5;
tt.tq="abcd";
COPYDATASTRUCT copydata;
copydata.dwData = CUSTOM_TYPE; //自定义用户号
copydata.lpData = &tt; //指向数据的指针
copydata.cbData = sizeof(tt); //数据大小
HWND sender = (HWND)effectiveWinId();
::SendMessage(hwnd,WM_COPYDATA,reinterpret_cast<WPARAM>(sender),reinterpret_cast<LPARAM>(©data));
}
2.接收方:
bool Receiver::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
MSG *param = static_cast<MSG *>(message);
switch(param->message)
{
case WM_COPYDATA:
{
COPYDATASTRUCT *cds = reinterpret_cast<COPYDATASTRUCT *>(param->lParam);
if(cds->dwData == CUSTOM_TYPE)
{
struct test
{
QSting tq;
float tf;
int ti;
}*tt;
tt = (test*)cds->lpData;
QMessageBox::information(this,QStringLiteral("字符串为:"),QString(tr("%1").arg(tt->tq)));
*result = 1;
return true;
}
}
}
return QWidget::nativeEvent(eventType,message,result);
}
经过断点发现,在这个进程间通信程序中,int型数据和float型数据都是正常的,但是QSting型数据无法识别?请问各位大神们,这是怎么回事?怎么才能在进程间通信中传送含有QString型数据的结构体?