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. Tons of error for no obvious reason

Tons of error for no obvious reason

Scheduled Pinned Locked Moved Solved General and Desktop
errorqt creator 4.14c++
13 Posts 5 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by Christian Ehrlicher
    #4

    Apart from the fact that there is no stacktrace but a compiler warning you should take a look at the file where the compiler generates the warnings for.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    1 Reply Last reply
    2
    • R Offline
      R Offline
      RekTekk249
      wrote on last edited by
      #5

      Is there more than the compile output and issues tab? Sorry, I'm new to qt and c++, where I come from the entire error obviously tells me where the issue is and what is causing it. I have checked the entire file it's sending me to, it's only a 30 line header file... It has not error that I can tell, nothing is underlined, the errors don't tell me anything and I can't seem to find out what's wrong.

      kshegunovK 1 Reply Last reply
      0
      • R RekTekk249

        Is there more than the compile output and issues tab? Sorry, I'm new to qt and c++, where I come from the entire error obviously tells me where the issue is and what is causing it. I have checked the entire file it's sending me to, it's only a 30 line header file... It has not error that I can tell, nothing is underlined, the errors don't tell me anything and I can't seem to find out what's wrong.

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by kshegunov
        #6

        You need to fix your form:

        ..\project4\mainwindow.ui: Warning: The name 'horizontalLayout' (QHBoxLayout) is already in use, defaulting to 'horizontalLayout1'.
        ..\project4\mainwindow.ui: Warning: The name 'horizontalLayout' (QHBoxLayout) is already in use, defaulting to 'horizontalLayout2'.

        means you have multiple objects with the same name.

        Aside from that this:

        C:\Users\etien\Documents\project4\loginwindow.h(22): error C2061: syntax error: identifier 'MainWindow'

        almost certainly means that you've not declared the MainWindow class at the point of usage. You need to either include the full declaration or forward declare the name. The compiler couldn't possibly know what MainWindow is supposed to mean otherwise.

        PS. As @Christian-Ehrlicher noted, the compiler tells you exactly where the problem was encountered - loginwindow.h at line 22.

        Read and abide by the Qt Code of Conduct

        R 1 Reply Last reply
        2
        • kshegunovK kshegunov

          You need to fix your form:

          ..\project4\mainwindow.ui: Warning: The name 'horizontalLayout' (QHBoxLayout) is already in use, defaulting to 'horizontalLayout1'.
          ..\project4\mainwindow.ui: Warning: The name 'horizontalLayout' (QHBoxLayout) is already in use, defaulting to 'horizontalLayout2'.

          means you have multiple objects with the same name.

          Aside from that this:

          C:\Users\etien\Documents\project4\loginwindow.h(22): error C2061: syntax error: identifier 'MainWindow'

          almost certainly means that you've not declared the MainWindow class at the point of usage. You need to either include the full declaration or forward declare the name. The compiler couldn't possibly know what MainWindow is supposed to mean otherwise.

          PS. As @Christian-Ehrlicher noted, the compiler tells you exactly where the problem was encountered - loginwindow.h at line 22.

          R Offline
          R Offline
          RekTekk249
          wrote on last edited by
          #7

          @kshegunov Alright, I'm starting to feel dumb here.

          In my main.cpp. I have:

          QApplication a(argc, argv);
          MainWindow *mw = new MainWindow();
          Helper *h = new Helper();
          LoginWindow *lw = new LoginWindow(mw, h);
          lw->setWindowFlag(Qt::MSWindowsFixedSizeDialogHint, true); /*No Resize*/
          lw->show();
          return a.exec();
          

          What do you mean by MainWindow not being declared before? While I understand that creating an object isn't a class declaration, if it can create that MainWindow instance just fine, why would it have any problems with the LoginWindow constructor?
          In that constructor, I use:

          LoginWindow::LoginWindow(MainWindow *mw, Helper *h, QWidget *parent)
              : QMainWindow(parent)
              , ui(new Ui::LoginWindow)
          {
              ui->setupUi(this);
              this->mainWindow = mw;
              this->helper = h;
              ....
          }
          

          It might be that doing it like that is not the best way, but this is what I came out with to keep the same instance of helper in both forms.

          Like, I see that line where the compiler tells me the error is, but that constructor has remained the same for the entirety of the project, why would it start telling me this now?

          As for the form warning, thanks for the insight, I didn't know there were warnings hidden in compile output that didn't make their way to issues.

          kshegunovK 1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #8

            Now two people told you where to look (in mainwindow.h) you still ignore us... I do the same with you. Good luck.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            0
            • R RekTekk249

              @kshegunov Alright, I'm starting to feel dumb here.

              In my main.cpp. I have:

              QApplication a(argc, argv);
              MainWindow *mw = new MainWindow();
              Helper *h = new Helper();
              LoginWindow *lw = new LoginWindow(mw, h);
              lw->setWindowFlag(Qt::MSWindowsFixedSizeDialogHint, true); /*No Resize*/
              lw->show();
              return a.exec();
              

              What do you mean by MainWindow not being declared before? While I understand that creating an object isn't a class declaration, if it can create that MainWindow instance just fine, why would it have any problems with the LoginWindow constructor?
              In that constructor, I use:

              LoginWindow::LoginWindow(MainWindow *mw, Helper *h, QWidget *parent)
                  : QMainWindow(parent)
                  , ui(new Ui::LoginWindow)
              {
                  ui->setupUi(this);
                  this->mainWindow = mw;
                  this->helper = h;
                  ....
              }
              

              It might be that doing it like that is not the best way, but this is what I came out with to keep the same instance of helper in both forms.

              Like, I see that line where the compiler tells me the error is, but that constructor has remained the same for the entirety of the project, why would it start telling me this now?

              As for the form warning, thanks for the insight, I didn't know there were warnings hidden in compile output that didn't make their way to issues.

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #9

              @RekTekk249 said in Tons of error for no obvious reason:

              What do you mean by MainWindow not being declared before?

              This is related to how C++ is compiled, which is in 'pieces'. A .cpp file (conditionally, but the finer details are unimportant here) defines a translation unit. The division of headers and sources is just semantics for us - people. The point is that when the compiler starts to build the translation unit, at each point a name is used, that name (a.k.a. identifier) has to be defined in some fashion. In your case, when the compiler compiles the translation units, it sees MainWindow, but it doesn't know what this name means. Is it a class, is it a variable of some type, an enum, a constant or whatever? That's why it complains, it needs to know before that. Consider this:

              int main()
              {
                  SomeIdentifier * a; //< What is `SomeIdentifier`? Is it `int`, is it a class, is it something else, the compiler can't know at this point
                  return 0;
              }
              

              Changing it to:

              class SomeIdentifier;
              int main()
              {
                  SomeIdentifier * a; //< Ah, okay, the compiler now knows that this name is the name of a class
                  return 0;
              }
              

              will compile fine.

              So in your file, the constructor in question references MainWindow, but the compiler doesn't know what MainWindow is.

              Read and abide by the Qt Code of Conduct

              R 1 Reply Last reply
              2
              • kshegunovK kshegunov

                @RekTekk249 said in Tons of error for no obvious reason:

                What do you mean by MainWindow not being declared before?

                This is related to how C++ is compiled, which is in 'pieces'. A .cpp file (conditionally, but the finer details are unimportant here) defines a translation unit. The division of headers and sources is just semantics for us - people. The point is that when the compiler starts to build the translation unit, at each point a name is used, that name (a.k.a. identifier) has to be defined in some fashion. In your case, when the compiler compiles the translation units, it sees MainWindow, but it doesn't know what this name means. Is it a class, is it a variable of some type, an enum, a constant or whatever? That's why it complains, it needs to know before that. Consider this:

                int main()
                {
                    SomeIdentifier * a; //< What is `SomeIdentifier`? Is it `int`, is it a class, is it something else, the compiler can't know at this point
                    return 0;
                }
                

                Changing it to:

                class SomeIdentifier;
                int main()
                {
                    SomeIdentifier * a; //< Ah, okay, the compiler now knows that this name is the name of a class
                    return 0;
                }
                

                will compile fine.

                So in your file, the constructor in question references MainWindow, but the compiler doesn't know what MainWindow is.

                R Offline
                R Offline
                RekTekk249
                wrote on last edited by
                #10

                @kshegunov I get this example, but I don't get how it applies to multiple files/classes. How is one declared before the other is read? I guess that means LoginWindow is "read" before MainWindow?

                On a side note, I've copied the EXACT same code, ui, and .pro file to another project and suddently...... it works.......
                I have literally no clue how that could be, but the only file I haven't copied over was .pro.user file.

                @Christian-Ehrlicher I am sorry if that's how you took it. I was so focused on the line the error was that I hadn't thought of looking in the actual class. But if copying the project over fixed it, does that mean I wasn't so dumb after all, or it maybe it was a simple thing that someone more experienced would have spent 5 minutes on rather than multiple hours.

                Anyway, thanks everyone, from now on, I'll be using git. No way this is happening again.

                kshegunovK 1 Reply Last reply
                0
                • R RekTekk249

                  @kshegunov I get this example, but I don't get how it applies to multiple files/classes. How is one declared before the other is read? I guess that means LoginWindow is "read" before MainWindow?

                  On a side note, I've copied the EXACT same code, ui, and .pro file to another project and suddently...... it works.......
                  I have literally no clue how that could be, but the only file I haven't copied over was .pro.user file.

                  @Christian-Ehrlicher I am sorry if that's how you took it. I was so focused on the line the error was that I hadn't thought of looking in the actual class. But if copying the project over fixed it, does that mean I wasn't so dumb after all, or it maybe it was a simple thing that someone more experienced would have spent 5 minutes on rather than multiple hours.

                  Anyway, thanks everyone, from now on, I'll be using git. No way this is happening again.

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by kshegunov
                  #11

                  @RekTekk249 said in Tons of error for no obvious reason:

                  I get this example, but I don't get how it applies to multiple files/classes. How is one declared before the other is read? I guess that means LoginWindow is "read" before MainWindow?

                  There's no multiple files, not auto-magically as you think of it at least. There's 3 passes:

                  1. The preprocessor: That expands all the preprocessor directives, and and your case notably the #includes. The include is literally replacing the referenced file in place of the #include directive.
                  2. The compiler: Each file resulting from the above step is passed through the compiler (and if you're missing the include(s) that declare(s) the names you get the error you got). Each such file produces one object file (also known as translation unit).
                  3. The linker: Taking all the object files (a.k.a. translation units) and puts them together into one binary (executable/library).

                  Read and abide by the Qt Code of Conduct

                  R 1 Reply Last reply
                  4
                  • kshegunovK kshegunov

                    @RekTekk249 said in Tons of error for no obvious reason:

                    I get this example, but I don't get how it applies to multiple files/classes. How is one declared before the other is read? I guess that means LoginWindow is "read" before MainWindow?

                    There's no multiple files, not auto-magically as you think of it at least. There's 3 passes:

                    1. The preprocessor: That expands all the preprocessor directives, and and your case notably the #includes. The include is literally replacing the referenced file in place of the #include directive.
                    2. The compiler: Each file resulting from the above step is passed through the compiler (and if you're missing the include(s) that declare(s) the names you get the error you got). Each such file produces one object file (also known as translation unit).
                    3. The linker: Taking all the object files (a.k.a. translation units) and puts them together into one binary (executable/library).
                    R Offline
                    R Offline
                    RekTekk249
                    wrote on last edited by
                    #12

                    @kshegunov I thank you for your insights. I have learned a lot today. I've gone back on the non working projet to try and see what could have been the issue and apparently it was as you people said, but I coudn't understand: the class was used as a type before it was declared. When I checked the includes, it seemed all good, until I learned about circular include problems or something like that. I had two classes including eachother, which caused this. As someone who comes from languages that allow you to import pretty much anything and fixes the issues for you, I did not know about this.

                    Thanks for enlightening me.

                    1 Reply Last reply
                    0
                    • R RekTekk249

                      Two hours ago, everything was going well, until I realised I needed the same instance of my helper class in my MainWindow than in my LoginWindow. Trying to make this work, I added a Helper parameter to both constructors and passed the same instance to these. However, at some point pressing build gave me 30+ errors. I have gone back to what I started pretty much everywhere, but the errors were still there. I've only changed the main class, which I have reverted to exactly the same, the LoginWindow and MainWindow cpp and h, but the cpp all I changed was the function signature and the this->helper = helper; part. I have also reverted the cpp as far as I know. The LoginWindow header is where every error is popping, but I have literally no clue what they mean. or even if they make sense here. I don't think I've ever hard to make such a post on my programming career, but after having spent two hours on this, I had to write this. Here's a screenshot of it, it shows every short error and the entire LoginWindow (also very short).

                      Alt-link: https://imgur.com/a/TnAZ560

                      Please help me out, while in a way I'm starting to feel like it's something stupid, I also fear that I broke the entire thing without having a backup. Never again am I thinking "I don't need git for this".

                      Pl45m4P Online
                      Pl45m4P Online
                      Pl45m4
                      wrote on last edited by Pl45m4
                      #13

                      @RekTekk249 said in Tons of error for no obvious reason:

                      Two hours ago, everything was going well, until I realised I needed the same instance of my helper class in my MainWindow than in my LoginWindow.

                      If you would have posted the whole file, esp. showing the parts you've changed, it would have saved a lot of troubleshooting ;-)

                      It's also a debugging thing... If you made changes and suddenly nothing works anymore, revert the changes and try to figure out why it happened.


                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                      ~E. W. Dijkstra

                      1 Reply Last reply
                      0

                      • Login

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