View Full Version : POSIX/Win32 Port involving QProcess, QSharedMemory

16th July 2010, 00:00
Hello all,

I am tasked with porting an MFC-based program to Qt4, and would like to set up as much groundwork as possible to make this app as much cross-platform as possible (at this time, certain hardware limitations prevent us from completely porting this to Linux).

The program spawns several processes and communicates with these processes using a shared memory segment set up like so:

HANDLE m_hMap;
LPVOID m_pSharedData;
// ...
void initSharedMemory() {
m_hMap=::CreateFileMapping((HANDLE)0xffffffff,0,PA GE_READWRITE,0,sizeof(RTC_DATA),MAPFILE);
m_pSharedData=::MapViewOfFile(m_hMap,FILE_MAP_WRIT E,0,0,0);

where RTC_DATA is the gobal struct containing the data and MAPFILE a #define.

The sub-processes are spawned like so:

ShellExecute( HWND(this), "open", "proc.exe", str_args, NULL, SW_HIDE);

Later in the code, the processes are being sent messages like this:

int SendMsgToProc(int procid, int cmd, long code, long code1)
char strtmp[10];
CWnd *pWnd;
pWnd = CWnd::FindWindow(NULL,strtmp);
WM_MSG msg;
msg.command = cmd;
msg.code = code;
msg.code1 = code1;
return 0;
return -1;

So far, I believe QProcess would be the right thing to do, and did the following:

QProcess *sub_proc = new QProcess(qApp);
// ... reading a configuration file ...
QStringList args = line.split("\s");

I also replaced the shared memory implementation with QSharedMemory. Now, however I need to be able to access these processes in a like manner as the "SendMsgToProc" function above.

Can anyone point me into the right direction? I know there is a WId for widgets, but would that even be feasible? Am I correct in attaching the QProcess instances to the global qApp?

I have no idea about MFC, and am only somewhat intermediate with Qt. If QProcess is not the right way to go, I would appreciate any comments as to what would be better.