Home > Back-end >  Open txt file through notepad using Qt
Open txt file through notepad using Qt

Time:02-01

I'm trying to open a text file in notepad using Qt but it keeps giving me this message:

enter image description here

What I'm using is the following: QProcess::startDetached("C:\\Windows\\system32\\notepad.exe", { ":/notes.txt" });

CodePudding user response:

You need to pass the full path to the file as an argument to the QProcess::startDetached() function. For example:

QProcess::startDetached("C:\\Windows\\system32\\notepad.exe", { "C:\\path\\to\\notes.txt" });

CodePudding user response:

Qt compiles resources added to a resource file into a binary format. Notepad (or any external tool) does not have access to the individual files that are part of it. If you want to provide access to the file to an external program, you'll have to either distribute your txt file alongside your application or write it to a temporary file on the fly before trying to open it.

After doing either of the two, you can then open your file with an external tool by passing the full path to QProcess::startDetached like it has been mentioned in David Cornejo's answer.

  •  Tags:  
  • qt
  • Related