Hi
I made a notepad in Qt and I want to open the file I double-clicked on my app
I used app arguments (QCoreApplication::arguments()), the second argument is the file path
It works perfectly when the file name is in English but when the file name is in Arabic, there are some problems
sometimes when the file name is in Arabic, the argument looks like this:
C:/the/file/path/???????. txt
And I can't open the file
but sometimes it works with no problems for example when the file name is(????????) I got it like(????????), but when it is(??) or (?? ????) it works.
(When I open the file via QFileDialog, it works fine with any file name)
what is the problem and how can I fix it?
and thanks
main.cpp:
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
using namespace std;
int main(int argc, char *argv[])
{
MainWindow w;
if(qApp->arguments().count() > 1)
w.openFile(qApp->arguments().at(1));
w.show();
return a.exec();
}
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
using namespace std;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
if(qApp->arguments().count() > 1)
w.openFile(qApp->arguments().at(1));
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
MainWindow::openFile(QString):
void MainWindow
::openFile(QString URL
)
{
else
{
text.setCodec("UTF-8");
QString fileContents
= text.
readAll();
TextEdit->setPlainText(fileContents);
file.close();
edited = false;
url = URL;
changeTitle();
}
}
void MainWindow::openFile(QString URL)
{
QFile file(URL);
if(!file.open(QFile::ReadOnly | QFile::Text))
QMessageBox::warning(this, "Error, Can't open the file", file.errorString(), QMessageBox::Ok);
else
{
QTextStream text(&file);
text.setCodec("UTF-8");
QString fileContents = text.readAll();
TextEdit->setPlainText(fileContents);
file.close();
edited = false;
url = URL;
changeTitle();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks