8

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?

6
  • 2
    That code looks fine, I think the problem must lie somewhere else. Are you sure you can reproduce the problem with this exact code?
    – hmn
    Commented Jun 14, 2013 at 11:31
  • 1
    Is that the whole header? If not make sure you don't have a forward declaration for QString class between the QString header include and the Process class declaration.
    – Zlatomir
    Commented Jun 14, 2013 at 11:32
  • It's the whole header. If I create empy project everything works fine. Commented Jun 14, 2013 at 11:56
  • But in my project there are lots of file, that use #include "process.h" and #include <QString>. Commented Jun 14, 2013 at 11:57
  • In this case Zlatomir is right. Something forward declares your class and does so before including your header. Search your code for "class QString" and see if you can avoid this.
    – user2471020
    Commented Jun 14, 2013 at 20:16

4 Answers 4

7

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 ;-)

0
1

Problem solved! Yes, it was because of class QString;, not in my files, but in some of QT's

1
  • 8
    And Can you explain your solution step by step? Because if someone else wrote here that problem solved , you would have wanted know solution. Commented Dec 13, 2019 at 11:48
1

Your mistake in the header file name becouse qt alredy have "process.h". I take similar error when create file "signal.h" and clear it when rename to "signal_db.h"

0

Commenting to add some clarification if anyone has this same issue. I also had a class with the name of "Process" which was the cause of this issue. I renamed the class, and the header protection to a slightly different string, in my case "AProcess"and that solved the issues.

1
  • This does not provide any contribution to the question except for repeating the other answer. You may upvote the relevant answers, once you have enough reputation. You may consider deleting this answer.
    – m7913d
    Commented Sep 14, 2020 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.