Removing red underlines in code



  • Hello,

    I am writing a piece of code that runs perfectly fine, but Qt Creator is giving me a red underline, and says 'expected a declaration'. As mentioned before, the code does everything as expected. Is there any way to remove this red underline?


  • Moderators

    Hard to tell without seeing the code that it's reporting.



  • Well is there anyway I can get rid of this misread?



  • Please give details of your environment and post the offending code



  • Hmm, Maybe the code works, but something is still wrong in your code! Never assume that Qt is wrong!! It normally is the code. Fix the code and the message disappears. Maybe the outcome of the error does the same as you want, but I wouldn't trust it to release the software. If you show the code that creator complains about we might be able to help.



  • Your code is wrong. I know it. Just review it.



  • There is no need for your code to be wrong; some combinations are just not supported by QtCreators code model yet, like C++11 features as non-static member initializers or Qt5 QStringLiteral.

    There is a transition from QtCreators own code model to clang, which should solve most of the problems. Until then feel free to file a "bug report":https://bugreports.qt-project.org/ so it gets fixed.

    I'm not aware of any possibility to disable syntax checking besides from recompiling QtCreator with it beeing disabled, but there is already a "feature request":https://bugreports.qt-project.org/browse/QTCREATORBUG-7552 for it beeing added (which, if this is important for you, should be voted on).

    However, it won't hurt if you post your problematic code as well, just because your compiler takes the code it doesn't mean it isn't wrong (and QtCreator complains rightly).



  • My code is indeed strange, as but I read that you can do this "thing" to derived classes to change the access specifier of a parent class's member. Here it is:

    @class Employee
    {
    public:
    Employee(string arg_Name, int arg_Age, int arg_Wage, int arg_HoursPerWeek);
    string Name;
    int Age;
    int Wage;
    int HoursPerWeek;

    void PrintMainInfo();
    

    protected:
    void PrintWage();
    };

    Employee::Employee(string arg_Name = "", int arg_Age = 0, int arg_Wage = 0, int arg_HoursPerWeek = 0) :
    Name(arg_Name), Age(arg_Age), Wage(arg_Wage), HoursPerWeek(arg_HoursPerWeek)
    {
    cout << "Creating Employee class" << "\n";
    }

    void Employee::PrintMainInfo()
    {
    cout << Name << "\n";
    }

    void Employee::PrintWage()
    {
    cout << Wage << "\n";
    }

    //////////////////////////////////////////////

    class Manager : private Employee
    {
    public:
    Manager(string arg_Name, int arg_Age, int arg_Wage, int arg_HoursPerWeek, int arg_PeopleToManage);
    int PeopleToManage;

    Employee::PrintWage; // RED UNDERLINE HERE
    

    };

    Manager::Manager(string arg_Name = "", int arg_Age = 0, int arg_Wage = 0, int arg_HoursPerWeek = 0, int arg_PeopleToManage = 0) :
    Employee(arg_Name, arg_Age, arg_Wage, arg_HoursPerWeek), PeopleToManage(arg_PeopleToManage)
    {
    }@



  • You should use using for access declarations (<code>using Employee::PrintWage</code>).

    In addition, default parameters should be specified in the declaration, not the definition.



  • @Lukas Geyer,

    Thanks! Putting the using worked. Never really thought much about its usage besides namespaces. Does using always work like this? It takes a member from a different scope, and puts it into the current scope?

    As for the default parameters, I will make sure to change them for future usage.



  • In principle, yes. C++11 allows you to do this for constructors as well.
    @
    class Manager : private Employee
    {
    using Employee::Employee; // invalid in C++98, valid in C++11
    };
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.