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. Why this code is not compiled?
Forum Updated to NodeBB v4.3 + New Features

Why this code is not compiled?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.4k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    dcbasso
    wrote on last edited by
    #1

    I try many ways to make this code works, but I don't know to fix it to work, or find another to do the same thing...
    Explanations?
    I will still reading to find the soluction! Thanks all!

    ProtocoloFactory.h
    @
    #ifndef PROTOCOLOFACTORY_H
    #define PROTOCOLOFACTORY_H

    #include <QObject>
    #include <bo/protocolo.h>

    class ProtocoloFactory : public QObject
    {
    Q_OBJECT
    public:
    explicit ProtocoloFactory(QObject *parent = 0);

    Protocolo createLerHistoricoComando();
    

    signals:

    public slots:

    };

    #endif // PROTOCOLOFACTORY_H
    @

    ProtocoloFactory.cpp
    @
    #include "protocolofactory.h"
    #include "bo/protocolo.h"

    ProtocoloFactory::ProtocoloFactory(QObject *parent) :
    QObject(parent)
    {
    }

    Protocolo ProtocoloFactory::createLerHistoricoComando()
    {
    Protocolo retorno(0);
    retorno.setOpcode(6);
    return retorno;
    }
    @

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SaiyanRiku
      wrote on last edited by
      #2

      What is your compiler output error?

      And why do you declare empty signal and slots section? If you don't use this, you don't need to declare these section.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dcbasso
        wrote on last edited by
        #3

        QtCreator Auto-Generates this section!

        Compiler error:
        .../InoveBEV/bo/protocolofactory.h:5: In file included from ../InoveBEV/bo/protocolofactory.h:5:0,
        .../InoveBEV/bo/protocolofactory.cpp:1: from ../InoveBEV/bo/protocolofactory.cpp:1:
        .../bin/QtSDK/Desktop/Qt/4.8.1/gcc/include/QtCore/qobject.h:-1: In copy constructor 'Protocolo::Protocolo(const Protocolo&)':
        .../bin/QtSDK/Desktop/Qt/4.8.1/gcc/include/QtCore/qobject.h:333: error: 'QObject::QObject(const QObject&)' is private
        .../InoveBEV/bo/protocolo.h:7: error: within this context
        .../InoveBEV/bo/protocolofactory.cpp:-1: In member function 'Protocolo ProtocoloFactory::createLerHistoricoComando()':
        .../InoveBEV/bo/protocolofactory.cpp:13: synthesized method 'Protocolo::Protocolo(const Protocolo&)' first required here

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          If Protocolo is a QObject, then your ProtocoloFactory::createLerHistoricoComando() method will not work, as it's relying on returning a copy of the Protocolo object created in line 11. QObjects are non-copyable by their nature.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dcbasso
            wrote on last edited by
            #5

            I that case I will need use Reference (*)?
            Or Cannot be done what I want?!

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #6

              You would need to use new to create the object on the heap and return a pointer to it, ideally a smart pointer.

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dcbasso
                wrote on last edited by
                #7

                Thanks mlong, I will do that and study the necessary.

                Thanks.

                1 Reply Last reply
                0

                • Login

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