Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: field has incomplete type

Tags:

c++

qt

Can't compile my class. Getting error: error: field 'filename' has incomplete type

If I change QString filename to QString *filename, error goes off.. but I need to have QString filename.

process.h:

#ifndef PROCESS_H
#define PROCESS_H

#include <QString>

class Process
{
public:
    int pid;
    QString filename;
    Process(int pid, QString filename);
};

#endif // PROCESS_H

process.cpp:

#include "process.h"

Process::Process(int pid, QString filename)
{
    this->pid = pid;
    this->filename = filename;
}

What's wrong?

like image 604
Denis Kildishev Avatar asked Jun 14 '13 11:06

Denis Kildishev


People also ask

Has incomplete type meaning?

An incomplete type is a type that describes an identifier but lacks information needed to determine the size of the identifier. An incomplete type can be: A structure type whose members you have not yet specified. A union type whose members you have not yet specified.

What is incomplete class type?

An "incomplete class" is one declared but not defined. E.g. class Wielrenner; as opposed to class Wielrenner { /* class members */ }; You need to #include "wielrenner.h" in dokter.ccp.

Can objects of class type that is declared but not defined be created?

You cannot declare any objects of the class type or refer to the members of a class until the declaration is complete. However, an incomplete declaration allows you to make specific references to a class prior to its definition as long as the size of the class is not required.


1 Answers

In my experience, when such weird errors like this appeared with no reason, most of the time it has been solved by changing some names, hence it was a name conflict. (but most of the time, I still didn't understand where was the conflict).

So I would desperately try to change the names of, in order:

  1. the name header protection PROCESS_H
  2. the name of the class Process
  3. the name of the member filename
  4. the name of the files process.h and process.cpp (if there are other folders with same file names, they will be compiled at the same place if you use qmake)
  5. the name of the member pid, because you are really desperate at this point

Use something you are really sure it can't be already used, like MySuperFancyProcess ;-)

like image 109
Boris Dalstein Avatar answered Sep 24 '22 14:09

Boris Dalstein