I have a problem with opening the double-clicked file in my Qt app
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:
Code:
#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();
}
MainWindow::openFile(QString):
Code:
void MainWindow
::openFile(QString URL
)
{
else
{
text.setCodec("UTF-8");
QString fileContents
= text.
readAll();
TextEdit->setPlainText(fileContents);
file.close();
edited = false;
url = URL;
changeTitle();
}
}
Re: I have a problem with opening the double-clicked file in my Qt app
I found a solution to this problem
the URL is coming from the system, so the problem with the system
I fixed that problem by enabling UTF-8 for windows by following these steps:
• Open Control Panel
• Click on Clock and Region
• Click on Region
• Go to Administrative tab
• Click on Change system locale...
• Click on Beta: Use Unicode UTF-8 for worldwide language support check box.
• Then when you restart your computer the problem will disappear :)