You'll need quotes around the file name to form the g++
command line:
cmd = "/c g++ \"" + openfiledialog.filename.toString() + "\" -o temp.exe";
Alternatively, you could post-process the value returned by .toString()
to insert an escape (backslash \
) character before each space. But the quote method is easier.