Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. The program doesn't show the contents of stored files

The program doesn't show the contents of stored files

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 5 Posters 1.8k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • tomyT Offline
    tomyT Offline
    tomy
    wrote on last edited by
    #1

    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?

    S 1 Reply Last reply
    0
    • tomyT tomy

      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?

      S Offline
      S Offline
      Stoyan
      wrote on last edited by
      #2

      @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.

      tomyT 1 Reply Last reply
      3
      • S Stoyan

        @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.

        tomyT Offline
        tomyT Offline
        tomy
        wrote on last edited by tomy
        #3

        @Stoyan

        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.

        jsulmJ 1 Reply Last reply
        0
        • tomyT tomy

          @Stoyan

          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.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @tomy

          QApplication app(argc, argv);
          MainWindow mainWin;
          if (argc > 1)
              mainWin.loadFile(argv[1]);
          

          See http://www.cprogramming.com/tutorial/lesson14.html

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          4
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            QCommandLineParser might also be a good idea.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • tomyT Offline
              tomyT Offline
              tomy
              wrote on last edited by
              #6

              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?

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                hi
                I think its not possible.
                Unless you call loadFile from main, i dont see any other way it could have worked before.

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved