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. New Errors when moving C++ code to QT Creator

New Errors when moving C++ code to QT Creator

Scheduled Pinned Locked Moved Solved General and Desktop
qtcreatorc++clanggcc
6 Posts 4 Posters 2.3k 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.
  • A Offline
    A Offline
    A123
    wrote on 12 Nov 2018, 01:56 last edited by A123 11 Dec 2018, 02:00
    #1

    I'm getting new errors when migrating from using makefiles and clang 4.0.1 on linux mint to using QTcreator as an IDE for convenience. Specifically its complaining that private members are being accessed.... 'is private within this context.' type error

    ie this line gives me an error

     assert( variableIndex(0,i)<organism_->numParameter());
    

    because

    private:
     
     // A pointer to the organism class to be able to get all possible data fields 
     Organism *organism_;
    

    I sorta understand the error but this is the way the code was when I received it, its been used by others for years and it worked perfectly AFAIK with gcc and clang before I started using qtcreator which complained. So I don't want to change it unless I'm sure the code is the problem. So what is wrong? Is it the code or one of the compilers? If you want to see additional code for context I can provide it. The old makefiles appear to include the problematic files so it doesn't look like just a matter of the errors only appearing when a previously unused file was included.

    J J 2 Replies Last reply 12 Nov 2018, 05:34
    0
    • A A123
      12 Nov 2018, 01:56

      I'm getting new errors when migrating from using makefiles and clang 4.0.1 on linux mint to using QTcreator as an IDE for convenience. Specifically its complaining that private members are being accessed.... 'is private within this context.' type error

      ie this line gives me an error

       assert( variableIndex(0,i)<organism_->numParameter());
      

      because

      private:
       
       // A pointer to the organism class to be able to get all possible data fields 
       Organism *organism_;
      

      I sorta understand the error but this is the way the code was when I received it, its been used by others for years and it worked perfectly AFAIK with gcc and clang before I started using qtcreator which complained. So I don't want to change it unless I'm sure the code is the problem. So what is wrong? Is it the code or one of the compilers? If you want to see additional code for context I can provide it. The old makefiles appear to include the problematic files so it doesn't look like just a matter of the errors only appearing when a previously unused file was included.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 12 Nov 2018, 05:34 last edited by
      #2

      @A123 said in New Errors when moving C++ code to QT Creator:

      So what is wrong?

      Accessing private members is wrong. There is a reason why they are private. You should fix the code.
      Also, where exactly is this code called

      assert( variableIndex(0,i)<organism_->numParameter());
      

      ?
      Is it called in the same class where organism_ is declared?

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

      A 1 Reply Last reply 12 Nov 2018, 07:36
      2
      • J jsulm
        12 Nov 2018, 05:34

        @A123 said in New Errors when moving C++ code to QT Creator:

        So what is wrong?

        Accessing private members is wrong. There is a reason why they are private. You should fix the code.
        Also, where exactly is this code called

        assert( variableIndex(0,i)<organism_->numParameter());
        

        ?
        Is it called in the same class where organism_ is declared?

        A Offline
        A Offline
        A123
        wrote on 12 Nov 2018, 07:36 last edited by
        #3

        @jsulm its called within a function of Class ParamCopy. ParamCopy is derived from BaseReact which is where

        private:
        
         Organism *organism_;
        

        is

        J 1 Reply Last reply 12 Nov 2018, 07:42
        0
        • A A123
          12 Nov 2018, 07:36

          @jsulm its called within a function of Class ParamCopy. ParamCopy is derived from BaseReact which is where

          private:
          
           Organism *organism_;
          

          is

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 12 Nov 2018, 07:42 last edited by
          #4

          @A123 Well, then this code is broken and I'm wondering how it was compiling before. Private elements of a base class can't be accessed from derived classes in C++. This is the case since the beginning of C++. You need to fix the code.

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

          1 Reply Last reply
          2
          • V Offline
            V Offline
            VRonin
            wrote on 12 Nov 2018, 08:32 last edited by
            #5

            To make it more clear, protected: would work, private: can't work

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            3
            • A A123
              12 Nov 2018, 01:56

              I'm getting new errors when migrating from using makefiles and clang 4.0.1 on linux mint to using QTcreator as an IDE for convenience. Specifically its complaining that private members are being accessed.... 'is private within this context.' type error

              ie this line gives me an error

               assert( variableIndex(0,i)<organism_->numParameter());
              

              because

              private:
               
               // A pointer to the organism class to be able to get all possible data fields 
               Organism *organism_;
              

              I sorta understand the error but this is the way the code was when I received it, its been used by others for years and it worked perfectly AFAIK with gcc and clang before I started using qtcreator which complained. So I don't want to change it unless I'm sure the code is the problem. So what is wrong? Is it the code or one of the compilers? If you want to see additional code for context I can provide it. The old makefiles appear to include the problematic files so it doesn't look like just a matter of the errors only appearing when a previously unused file was included.

              J Offline
              J Offline
              JKSH
              Moderators
              wrote on 13 Nov 2018, 06:12 last edited by JKSH
              #6

              @A123 said in New Errors when moving C++ code to QT Creator:

              its been used by others for years and it worked perfectly AFAIK with gcc and clang before I started using qtcreator which complained.

              Here's my guess: Previously, the assert() macro was disabled. This caused the illegal code to be effectively "commented out", so the compiler didn't detect it. After the migration, the assert() macro was no longer disabled, so the compiler now sees the bad code and (correctly) complains.

              See http://www.cplusplus.com/reference/cassert/assert/. You could make your code work again by defining the NDEBUG macro, but be careful: This will disable all assert()s which might cause other errors to go undetected.

              P.S. The compiler is the one that complained, not Qt Creator.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              5

              6/6

              13 Nov 2018, 06:12

              • Login

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