PDA

View Full Version : 'Open with' & compiler problems



SenseiTakeshi
13th March 2016, 12:25
Hello, i'm trying to make a text edit but i've problems with "open with".
I would like that when i'm on my desktop and right click on a file (.txt for instance) -> open with -> MyApp, the text shows in a QTextEdit

For now, i've that :


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QString file = QFileDialog::getOpenFileName(this, "Open a file", "", tr("Text files (*.txt) ;; All files (*.*)") );

if ( !file.isEmpty() )
{
QFile sFile ( file );
if ( sFile.open(QFile::ReadOnly | QFile::Text) )
{
QTextStream in(&sFile);
QString text = in.readAll();
sFile.close();

ui->textEdit->setPlainText(text);
}
}
}

But it doesn't do what I would like. :'(

---------------------------------------------

My second problem is when I call :



QFileDialog::getOpenFileName
or
QFileDialog::getSaveFileName


there is a little message in debug :



shell\comdlg32\fileopensave.cpp(9456)\COMDLG32.DLL !764F0750: (caller: 764E3458) ReturnHr[PreRelease](1) tid(630) 80070490 Element not found.
CallContext:[\PickerModalLoop\InitDialog\FileDialogInitEnterpri seData]


despite this, it works anyway. How can i solve this "false" error ?

Added after 1 3 minutes:

i solved my first problem, I used



if (QApplication::arguments().size() > 1) {
const QString FILENAME = QApplication::arguments().at(1));
}


so it returns me the path and the name of the file i wanna open.
source : http://stackoverflow.com/questions/31360330/how-to-open-file-in-qt-application

-----------------

My second problem is still unsolved.