Results 1 to 2 of 2

Thread: Problems communicating with external editor

  1. #1
    Join Date
    Sep 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Problems communicating with external editor

    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?

  2. #2
    Join Date
    Sep 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Problems communicating with external editor

    Since QProcess does not emulate a shell I figured that I might need to provide one so I tried the following:

    Qt Code:
    1. QProcess::execute("/bin/sh", QStringList() << "-c" << (QString("'") + "vim" + " " + fileName + "'"));
    To copy to clipboard, switch view to plain text mode 

    However, when I run this, it prints:

    /bin/sh: vim /var/folders/1R/1RaTXd1DHFu0ASTg0KYfqE+++TM/-Tmp-/qt_temp.JL2217: No such file or directory
    However, if I execute the command "/bin/sh -c 'vim var/folders/1R/1RaTXd1DHFu0ASTg0KYfqE+++TM/-Tmp-/qt_temp.JL2217'" the vim editor opens and allows me to edit a new file.

    Help!

Similar Threads

  1. Q3ScrollView resists to scroll down to the garbage bin
    By sivrisinek in forum Qt Programming
    Replies: 0
    Last Post: 5th February 2009, 17:50
  2. shared vs static
    By alisami in forum Installation and Deployment
    Replies: 3
    Last Post: 4th October 2008, 13:04
  3. Replies: 16
    Last Post: 23rd May 2008, 10:12
  4. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.