I am writing a command-line Qt4 script (using QCoreApplication) on Mac OS X.

I am using this code adapted from C++ Programming with Qt 4, 2nd ed. p. 313:

Qt Code:
  1. if (!outFile.open())
  2. return;
  3.  
  4. QString fileName = outFile.fileName();
  5. QTextStream out(&outFile);
  6. out << initial_text;
  7. outFile.close();
  8.  
  9. QProcess::execute(editor, QStringList() << fileName);
  10.  
  11. QFile inFile(fileName);
  12. if (!inFile.open(QIODevice::ReadOnly))
  13. return;
  14.  
  15. QTextStream in(&inFile);
  16. QString text = in.readAll();
  17.  
  18. std::cout << text.toStdString() << std::endl;
To copy to clipboard, switch view to plain text mode 

When the above is run with editor set to "/usr/bin/vim", "Vim: Warning: Input is not from terminal" is printed, then vim launches with the initial text (the string initial_text); however, I am unable to edit or quit because pressing escape prints a blue ^[ at the position of the cursor, b prints a blue b, and so on.

When editor is instead set to "/Users/jason/bin/mate" (the TextMate command-line utility), TextMate launches, without the initial text. I can edit and save the document, and when I quit, the application reads in the initial text (which should have been overwritten).

I am puzzled since this code is in a printed book so it should work. Am I using the wrong strings for the editor variable?