Solved The program doesn't show the contents of stored files
-
Hi all,
Here is the program from the book "C++-GUI-Programming-with-Qt-4-2nd Edition". I tested that code on Qt Creator 4.3.0, Qt 5.9 and ran it. Then using Qt Installer Framework (some folders, .dll files, a script file and the Release version of .exe file of the app and ect) created an installer for the app.
It works fine, but there is an odd problem!When I create an new Spreadsheet file and put some contents into it. Then store it somewhere, say, Desktop, the stored file has some size (because of its contents) but when using double click I open it by the Spreadsheet app, the app doesn't show any content in the file!! But when I open that file using the Open button on the app, the app this time shows the content correctly!!
I don't know what the issue is. If my recollection is accurate, it worked well the times before, but why not now?!!
Do you have any idea in mind about it please?
-
@tomy
In your application you don't use argc and argv. They are used to pass arguments from command line. When you open a file with double click, the name of the file will be set as argument for your application.
And by default your application starts with a new file (Spreadsheet).
You should handle argc and argv and pass file name to loadFile function. -
In your application you don't use argc and argv. They are used to pass arguments from command line. When you open a file with double click, the name of the file will be set as argument for your application.
And by default your application starts with a new file (Spreadsheet).It's good information, thanks.
You should handle argc and argv and pass file name to loadFile function.
Yes, but how to do that, please?
This is my
main()
:#include <QApplication> #include "mainwindow.h" int main(int argc, char* argv[]) { QApplication app(argc, argv); MainWindow mainWin; mainWin.show(); return app.exec(); }
And this is
loadFile()
:bool MainWindow::loadFile(const QString &fileName) { if (!spreadsheet->readFile(fileName)) { statusBar()->showMessage(tr("Loading canceled"), 3000); return false; } setCurrentFile(fileName); statusBar()->showMessage(tr("File loaded"), 3000); return true; }
Would you please guide me on that? I haven't done it before.
-
QApplication app(argc, argv); MainWindow mainWin; if (argc > 1) mainWin.loadFile(argv[1]);
-
Hi,
QCommandLineParser might also be a good idea.
-
Thank you all. I used jsulm's means. The problem is solved but let me please ask this question.
Although I don't remember either jsulm's or SGaist's method has been used in the code, I think it worked before! If my recollection is accurate enough the program would work with double clicking the stored files and showing their contents even before using those methods. Of course I'm not sure.Do you think it could be possible?
-
hi
I think its not possible.
Unless you call loadFile from main, i dont see any other way it could have worked before.