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:
if (!outFile.open())
return;
QString fileName
= outFile.
fileName();
out << initial_text;
outFile.close();
return;
std::cout << text.toStdString() << std::endl;
QTemporaryFile outFile;
if (!outFile.open())
return;
QString fileName = outFile.fileName();
QTextStream out(&outFile);
out << initial_text;
outFile.close();
QProcess::execute(editor, QStringList() << fileName);
QFile inFile(fileName);
if (!inFile.open(QIODevice::ReadOnly))
return;
QTextStream in(&inFile);
QString text = in.readAll();
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?
Bookmarks