title: Multiple definition of error in QSerialPort using QT Creator
body: <p>I recently started working on my final project to complete my study. In this project I have to continue with the work from a previous student which requires me to use QT Creator, unknown for me.
  The project thus far is a UI application used to receive data from an Arducopter using serial communication.</p>
  
  <p>When I try to compile the code the following errors pop-up:</p>
  
  <pre><code>C:\Qt\Qt5.1.1\5.1.1\mingw48_32\lib\libQt5SerialPortd.a(d000044.o):-1: error: multiple definition of `QSerialPort::error(QSerialPort::SerialPortError)'
  debug\moc_qserialport.o:D:\Development\Code\QTWorkspace\build-BEP-Desktop_Qt_5_1_1_MinGW_32bit-Debug\debug\moc_qserialport.cpp:520: error: first defined here
  C:\Qt\Qt5.1.1\5.1.1\mingw48_32\lib\libQt5SerialPortd.a(d000012.o):-1: error: multiple definition of `QSerialPort::qt_metacast(char const*)'
  debug\moc_qserialport.o:D:\Development\Code\QTWorkspace\build-BEP-Desktop_Qt_5_1_1_MinGW_32bit-Debug\debug\moc_qserialport.cpp:387: error: first defined here
  C:\Qt\Qt5.1.1\5.1.1\mingw48_32\lib\libQt5SerialPortd.a(d000011.o):-1: error: multiple definition of `QSerialPort::qt_metacall(QMetaObject::Call, int, void**)'
  debug\moc_qserialport.o:D:\Development\Code\QTWorkspace\build-BEP-Desktop_Qt_5_1_1_MinGW_32bit-Debug\debug\moc_qserialport.cpp:395: error: first defined here
  collect2.exe:-1: error: error: ld returned 1 exit status
  </code></pre>
  
  <p>The project only contains the following header files, not the corresponding .cpp files:</p>
  
  <pre><code>qserialport.h
  qserialportglobal.h
  qserialportinfo.h
  </code></pre>
  
  <p>These are the files;
  qserialportglobal.h:</p>
  
  <pre><code>#ifndef QSERIALPORTGLOBAL_H
  #define QSERIALPORTGLOBAL_H
  
  #include &lt;QtCore/qglobal.h&gt;
  
  QT_BEGIN_NAMESPACE
  
  #ifndef QT_STATIC
  #  if defined(QT_BUILD_SERIALPORT_LIB)
  #    define Q_SERIALPORT_EXPORT Q_DECL_EXPORT
  #  else
  #    define Q_SERIALPORT_EXPORT Q_DECL_IMPORT
  #  endif
  #else
  #  define Q_SERIALPORT_EXPORT
  #endif
  
  // The macro has been available only since Qt 5.0
  #ifndef Q_DECL_OVERRIDE
  #define Q_DECL_OVERRIDE
  #endif
  
  QT_END_NAMESPACE
  
  #endif // QSERIALPORTGLOBAL_H
  </code></pre>
  
  <p>qserialportinfo.h:</p>
  
  <pre><code>    #ifndef QSERIALPORTINFO_H
  #define QSERIALPORTINFO_H
  
  #include &lt;QtCore/qlist.h&gt;
  #include &lt;QtCore/qscopedpointer.h&gt;
  
  #include &lt;QtSerialPort/qserialportglobal.h&gt;
  
  QT_BEGIN_NAMESPACE
  
  class QSerialPort;
  class QSerialPortInfoPrivate;
  class QSerialPortInfoPrivateDeleter;
  
  class Q_SERIALPORT_EXPORT QSerialPortInfo
  {
      Q_DECLARE_PRIVATE(QSerialPortInfo)
  public:
      QSerialPortInfo();
      explicit QSerialPortInfo(const QSerialPort &amp;port);
      explicit QSerialPortInfo(const QString &amp;name);
      QSerialPortInfo(const QSerialPortInfo &amp;other);
      ~QSerialPortInfo();
  
      QSerialPortInfo&amp; operator=(const QSerialPortInfo &amp;other);
      void swap(QSerialPortInfo &amp;other);
  
      QString portName() const;
      QString systemLocation() const;
      QString description() const;
      QString manufacturer() const;
  
      quint16 vendorIdentifier() const;
      quint16 productIdentifier() const;
  
      bool hasVendorIdentifier() const;
      bool hasProductIdentifier() const;
  
      bool isNull() const;
      bool isBusy() const;
      bool isValid() const;
  
      static QList&lt;qint32&gt; standardBaudRates();
      static QList&lt;QSerialPortInfo&gt; availablePorts();
  
  private:
      QScopedPointer&lt;QSerialPortInfoPrivate, QSerialPortInfoPrivateDeleter&gt; d_ptr;
  };
  
  inline bool QSerialPortInfo::isNull() const
  { return !d_ptr; }
  
  QT_END_NAMESPACE
  
  #endif // QSERIALPORTINFO_H
  </code></pre>
  
  <p>And qserialport.h:</p>
  
  <pre><code>    #ifndef QSERIALPORT_H
  #define QSERIALPORT_H
  
  #include &lt;QtCore/qiodevice.h&gt;
  
  #include &lt;QtSerialPort/qserialportglobal.h&gt;
  
  QT_BEGIN_NAMESPACE
  
  class QSerialPortInfo;
  class QSerialPortPrivate;
  
  class Q_SERIALPORT_EXPORT QSerialPort : public QIODevice
  {
      Q_OBJECT
  
      Q_PROPERTY(qint32 baudRate READ baudRate WRITE setBaudRate NOTIFY baudRateChanged)
      Q_PROPERTY(DataBits dataBits READ dataBits WRITE setDataBits NOTIFY dataBitsChanged)
      Q_PROPERTY(Parity parity READ parity WRITE setParity NOTIFY parityChanged)
      Q_PROPERTY(StopBits stopBits READ stopBits WRITE setStopBits NOTIFY stopBitsChanged)
      Q_PROPERTY(FlowControl flowControl READ flowControl WRITE setFlowControl NOTIFY flowControlChanged)
      Q_PROPERTY(DataErrorPolicy dataErrorPolicy READ dataErrorPolicy WRITE setDataErrorPolicy NOTIFY dataErrorPolicyChanged)
      Q_PROPERTY(bool dataTerminalReady READ isDataTerminalReady WRITE setDataTerminalReady NOTIFY dataTerminalReadyChanged)
      Q_PROPERTY(bool requestToSend READ isRequestToSend WRITE setRequestToSend NOTIFY requestToSendChanged)
      Q_PROPERTY(SerialPortError error READ error RESET clearError NOTIFY error)
      Q_PROPERTY(bool settingsRestoredOnClose READ settingsRestoredOnClose WRITE setSettingsRestoredOnClose NOTIFY settingsRestoredOnCloseChanged)
  
      Q_ENUMS( Directions Rate DataBits Parity StopBits FlowControl PinoutSignals DataErrorPolicy SerialPortError )
  
  public:
  
      enum Direction  {
          Input = 1,
          Output = 2,
          AllDirections = Input | Output
      };
      Q_DECLARE_FLAGS(Directions, Direction)
  
      enum BaudRate {
          Baud1200 = 1200,
          Baud2400 = 2400,
          Baud4800 = 4800,
          Baud9600 = 9600,
          Baud19200 = 19200,
          Baud38400 = 38400,
          Baud57600 = 57600,
          Baud115200 = 115200,
          UnknownBaud = -1
      };
  
      enum DataBits {
          Data5 = 5,
          Data6 = 6,
          Data7 = 7,
          Data8 = 8,
          UnknownDataBits = -1
      };
  
      enum Parity {
          NoParity = 0,
          EvenParity = 2,
          OddParity = 3,
          SpaceParity = 4,
          MarkParity = 5,
          UnknownParity = -1
      };
  
      enum StopBits {
          OneStop = 1,
          OneAndHalfStop = 3,
          TwoStop = 2,
          UnknownStopBits = -1
      };
  
      enum FlowControl {
          NoFlowControl,
          HardwareControl,
          SoftwareControl,
          UnknownFlowControl = -1
      };
  
      enum PinoutSignal {
          NoSignal = 0x00,
          TransmittedDataSignal = 0x01,
          ReceivedDataSignal = 0x02,
          DataTerminalReadySignal = 0x04,
          DataCarrierDetectSignal = 0x08,
          DataSetReadySignal = 0x10,
          RingIndicatorSignal = 0x20,
          RequestToSendSignal = 0x40,
          ClearToSendSignal = 0x80,
          SecondaryTransmittedDataSignal = 0x100,
          SecondaryReceivedDataSignal = 0x200
      };
      Q_DECLARE_FLAGS(PinoutSignals, PinoutSignal)
  
      enum DataErrorPolicy {
          SkipPolicy,
          PassZeroPolicy,
          IgnorePolicy,
          StopReceivingPolicy,
          UnknownPolicy = -1
      };
  
      enum SerialPortError {
          NoError,
          DeviceNotFoundError,
          PermissionError,
          OpenError,
          ParityError,
          FramingError,
          BreakConditionError,
          WriteError,
          ReadError,
          ResourceError,
          UnsupportedOperationError,
          UnknownError
      };
  
      explicit QSerialPort(QObject *parent = 0);
      explicit QSerialPort(const QString &amp;name, QObject *parent = 0);
      explicit QSerialPort(const QSerialPortInfo &amp;info, QObject *parent = 0);
      virtual ~QSerialPort();
  
      void setPortName(const QString &amp;name);
      QString portName() const;
  
      void setPort(const QSerialPortInfo &amp;info);
  
      bool open(OpenMode mode) Q_DECL_OVERRIDE;
      void close() Q_DECL_OVERRIDE;
  
      void setSettingsRestoredOnClose(bool restore);
      bool settingsRestoredOnClose() const;
  
      bool setBaudRate(qint32 baudRate, Directions dir = AllDirections);
      qint32 baudRate(Directions dir = AllDirections) const;
  
      bool setDataBits(DataBits dataBits);
      DataBits dataBits() const;
  
      bool setParity(Parity parity);
      Parity parity() const;
  
      bool setStopBits(StopBits stopBits);
      StopBits stopBits() const;
  
      bool setFlowControl(FlowControl flow);
      FlowControl flowControl() const;
  
      bool setDataTerminalReady(bool set);
      bool isDataTerminalReady();
  
      bool setRequestToSend(bool set);
      bool isRequestToSend();
  
      PinoutSignals pinoutSignals();
  
      bool flush();
      bool clear(Directions dir = AllDirections);
      bool atEnd() const Q_DECL_OVERRIDE;
  
      bool setDataErrorPolicy(DataErrorPolicy policy = IgnorePolicy);
      DataErrorPolicy dataErrorPolicy() const;
  
      SerialPortError error() const;
      void clearError();
  
      qint64 readBufferSize() const;
      void setReadBufferSize(qint64 size);
  
      bool isSequential() const Q_DECL_OVERRIDE;
  
      qint64 bytesAvailable() const Q_DECL_OVERRIDE;
      qint64 bytesToWrite() const Q_DECL_OVERRIDE;
      bool canReadLine() const Q_DECL_OVERRIDE;
  
      bool waitForReadyRead(int msecs) Q_DECL_OVERRIDE;
      bool waitForBytesWritten(int msecs) Q_DECL_OVERRIDE;
  
      bool sendBreak(int duration = 0);
      bool setBreakEnabled(bool set = true);
  
  Q_SIGNALS:
      void baudRateChanged(qint32 baudRate, QSerialPort::Directions dir);
      void dataBitsChanged(QSerialPort::DataBits dataBits);
      void parityChanged(QSerialPort::Parity parity);
      void stopBitsChanged(QSerialPort::StopBits stopBits);
      void flowControlChanged(QSerialPort::FlowControl flow);
      void dataErrorPolicyChanged(QSerialPort::DataErrorPolicy policy);
      void dataTerminalReadyChanged(bool set);
      void requestToSendChanged(bool set);
      void error(QSerialPort::SerialPortError serialPortError);
      void settingsRestoredOnCloseChanged(bool restore);
  
  protected:
      qint64 readData(char *data, qint64 maxSize) Q_DECL_OVERRIDE;
      qint64 readLineData(char *data, qint64 maxSize) Q_DECL_OVERRIDE;
      qint64 writeData(const char *data, qint64 maxSize) Q_DECL_OVERRIDE;
  
  private:
      void setError(QSerialPort::SerialPortError error, const QString &amp;errorString = QString());
  
      QSerialPortPrivate * const d_ptr;
  
      Q_DECLARE_PRIVATE(QSerialPort)
      Q_DISABLE_COPY(QSerialPort)
  };
  
  Q_DECLARE_OPERATORS_FOR_FLAGS(QSerialPort::Directions)
  Q_DECLARE_OPERATORS_FOR_FLAGS(QSerialPort::PinoutSignals)
  
  QT_END_NAMESPACE
  
  #endif // QSERIALPORT_H
  </code></pre>
  
  <p>As seen in the description the errors seem to occur in a moc_ file, I'm not familiar with these files, but after some research I found out that these files are and extension to signal functions?
  The other side of the error is found in a standard library, I have not changed anything ever in these files.</p>
  
  <p>Help is very much appreciated, I have been stuck for a couple of days now.</p>