You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Friday, September 23rd 2011, 2:48pm

error: no matching function for call to... which means this error?

Hi everyone,
I'm programming with QT in Windows, and I have a building error, this is error:
"no matching function for call to 'devices:: Phase:: Phase()"
I do not understand if it is generated because I have an error in the declaration of my class and I make the call QObject, this is my class

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  class Plan : public QObject   {
     Q_OBJECT
      protected:
       devices::Phase phase; //!< fases asociadas al plan
       QTime time; //!< Hora del servidor
       int cycle; //!< valor del ciclo
       components::PointerList<devices::Phase*> phases; //!< fases asociadas
       QHash<QString, devices::Phase*> _phases; //!< Lista de ID de las fases del plan
      public:
        /*!
         Constructor.
         \param phase lista de fases de la intersección
         \param time hora del servidor
         \param cycle valor en segundos del ciclo de duración del plan
         */
       //pendiente por cambiar el Qlist por el Objeto fase
       Plan (Phase phase, QTime time, int cycle);
   }







the error is generated in this part of code in my class Plan.cpp

Source code

1
2
3
4
5
6
7
Plan::Plan(Phase phase, QTime time, int cycle)   
: QObject() //HERE IS THE ERROR
 {
   this->phase = phase;
   this->time = time;
   this->cycle = cycle;
 }



which means this error?


I searched Google and I could not understand that this error is

This post has been edited 1 times, last edit by "yosma" (Sep 23rd 2011, 3:09pm)


2

Friday, September 23rd 2011, 3:37pm

Hi,

You probably don't have a standard constructor for your object Phase. It is needed for your class member Plan::phase.
Recap C++: All members of a class C are constructed before you enter the body of the constructor of that class. If you do not specify a specific constructor for the members, it simply takes the default one, which is the void-constructor. For a class B, this is simply B().

I suggest the following for your example:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 class Plan : public QObject
 {
    // ....
    Phase m_phase;
    QTime m_time;
    int m_cycle;
 };
 
Plan::Plan(Phase phase, QTime time, int cycle)
  : QObject(),
    m_phase(phase), // Call copy constructor of Phase
    m_time(time),   // Call copy constructor of QTime
    m_cycle(cycle)  // ...
 { }

3

Friday, September 23rd 2011, 5:02pm

"no matching function for call to 'devices:: Phase:: Phase()"

you are trying to use a default constructor, but it is not available on Phase
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

4

Friday, September 23rd 2011, 9:07pm

Thanks for all the help Amleto, appreciate it.. I fixed the error with your suggestion!
But, now i get this error in my class Phase.h:
error: 'QObject::QObject(const QObject&)' is private
error: within this context


Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Phase : public QObject 
 {
Q_OBJECT
      protected:
      QString id; //!< Identificador del dispositivo
      int value; //!< valor de la fase
       public:
      Phase (QString id, int value);
       
QString getId();
       void setId(QString id);
      int getValue();
      void setValue(int value);
    };


I guess that it's the same situation the previous error, as I understand you a subclass of QObject, cannot be copied

I read that, perhaps i could pass it to your function by const reference instead. But i don't have any idea how to do that.

I try to apply the same solution to the above problem, but did not work.

can you suggest me something?

my apologies, I'm really newbie at this :S

5

Saturday, September 24th 2011, 10:33am

is that all of your code for phase? I don't think so... it wont cause that error.

why do you need to inherit QObject?

You cannot use copy constructor for QObject - what is your code that causes the compiler error? Don't you think this would beuseful? ;) please tell us which line causes the error as well.


You have found two issues:

1) you dont have Phase()
2) you cant use QObject(const QObject&)

"I read that, perhaps i could pass it to your function by const reference instead."
that sounds like you just tried to do 2)
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

6

Thursday, October 6th 2011, 2:46pm

Hi Amleto, thanks for your help.
I finished the first phase of the project, and it worked. Thank you very much for your suggestions.

This post has been edited 1 times, last edit by "yosma" (Oct 6th 2011, 2:56pm)


Used tags

error, no matching