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. Open file with double click, syntax error

Open file with double click, syntax error

Scheduled Pinned Locked Moved Solved General and Desktop
mainmainwindowload
10 Posts 3 Posters 3.2k Views
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on 19 May 2016, 07:52 last edited by
    #1

    Hi everyone!

    I want to open a .htm file in my application by double clicking.
    So i have written These Code in main.cpp:

    for ( int i = 1; i < argc; ++i )
        mainWin.load(argv[i]);
    

    And These in mainwindow.h

    void load(char *fileName);
    

    And now i'm getting These Errors:

    C:\Users\Henrik\Documents\TextPad\mainwindow.h:147: Fehler: 'void MainWindow::load(char*)' is private
     void load(char *fileName);
          ^
    
    C:\Users\Henrik\Documents\TextPad\main.cpp:28: Fehler: within this context
         mainWin.load(argv[i]);
                             ^
    

    Does anybody know why the Errors are there and how to fix them?

    Thanks,
    Henrik

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 19 May 2016, 08:00 last edited by
      #2

      as the error says the load() method is private.
      But you are trying to access it "from the outside" of the class. Declare it as public.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 19 May 2016, 08:02 last edited by
        #3

        As the error message already says: you put load() in private section in your class, put it in public.

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

        ? 1 Reply Last reply 19 May 2016, 08:06
        0
        • J jsulm
          19 May 2016, 08:02

          As the error message already says: you put load() in private section in your class, put it in public.

          ? Offline
          ? Offline
          A Former User
          wrote on 19 May 2016, 08:06 last edited by
          #4

          @jsulm

          C:\Users\Henrik\Documents\TextPad\main.cpp:28: Fehler: undefined reference to `MainWindow::load(char*)'
          
          C:\Users\Henrik\Documents\build-TextPad-Desktop_Qt_5_5_1_MinGW_32bit2-Debug\debug\moc_mainwindow.cpp:350: Fehler: undefined reference to `MainWindow::load(char*)'
          
          1 Reply Last reply
          0
          • J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 19 May 2016, 08:09 last edited by
            #5

            Did you define load() method?
            I mean (usually) in cpp file:

            void MainWindow::load(char*)
            {
            
            }
            

            How experienced are you with C++?

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

            ? 1 Reply Last reply 19 May 2016, 08:10
            0
            • J jsulm
              19 May 2016, 08:09

              Did you define load() method?
              I mean (usually) in cpp file:

              void MainWindow::load(char*)
              {
              
              }
              

              How experienced are you with C++?

              ? Offline
              ? Offline
              A Former User
              wrote on 19 May 2016, 08:10 last edited by
              #6

              @jsulm
              No, i don't...
              What should i write in the method?

              My experiences are not so good... I read a lot of book... Reading the Code is no Problem but writing is very hard for me...

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 19 May 2016, 08:13 last edited by
                #7

                The method can be empty like in the example I gave.
                What you should write there is something you should know as it is your program.
                I guess you want to open a file and read its content, right? Then do it using QFile.

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

                ? 1 Reply Last reply 19 May 2016, 08:15
                0
                • J jsulm
                  19 May 2016, 08:13

                  The method can be empty like in the example I gave.
                  What you should write there is something you should know as it is your program.
                  I guess you want to open a file and read its content, right? Then do it using QFile.

                  ? Offline
                  ? Offline
                  A Former User
                  wrote on 19 May 2016, 08:15 last edited by
                  #8

                  @jsulm
                  Yes i want to open the file...

                   QString fileName = QFileDialog::getOpenFileName(this, tr("Öffnen..."),
                                                                     QString(), tr("TextPad 1.0 (*.htm);;"));
                     QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
                  
                     QFile file(fileName, this);
                  
                     if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
                     {
                        qDebug() << "Fehler beim Öffnen der Datei";
                     }
                  
                     if (document())
                     {
                        document()->clear();
                     }
                  
                     document()->setHtml(file.readAll());
                     file.close();
                  

                  Something like that?

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 19 May 2016, 08:46 last edited by
                    #9

                    You already pass file path as parameter to the load() method.
                    In this case there is no need for:

                    QString fileName = QFileDialog::getOpenFileName(this, tr("Öffnen..."),
                                                                       QString(), tr("TextPad 1.0 (*.htm);;"));
                    
                    // This line does not make any sence because you do not use its return value
                    QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
                    

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

                    ? 1 Reply Last reply 19 May 2016, 08:51
                    0
                    • J jsulm
                      19 May 2016, 08:46

                      You already pass file path as parameter to the load() method.
                      In this case there is no need for:

                      QString fileName = QFileDialog::getOpenFileName(this, tr("Öffnen..."),
                                                                         QString(), tr("TextPad 1.0 (*.htm);;"));
                      
                      // This line does not make any sence because you do not use its return value
                      QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
                      
                      ? Offline
                      ? Offline
                      A Former User
                      wrote on 19 May 2016, 08:51 last edited by
                      #10

                      @jsulm
                      Yes. I tried before your post and it works!

                      Thank you all...

                      1 Reply Last reply
                      0

                      3/10

                      19 May 2016, 08:02

                      7 unread
                      • Login

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