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. Problem on linker.
Qt 6.11 is out! See what's new in the release blog

Problem on linker.

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 287 Views
  • 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.
  • J Offline
    J Offline
    JonexElectronic
    wrote on last edited by
    #1

    Hello, I am a noob programmer and I am also new with QT. I have a problem on my code and I don't know how to resolve. Please help.

    Main.cpp

    #include <QCoreApplication>
    #include <QDebug>
    #include "persona.h"
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        QObject *p = new QObject;
        Persona* Juan = new Persona(p);
        Juan->setNombre("Juan");
    
        qDebug() << Juan;
        
        delete p;
        return a.exec();
    }
    --------------------------------------------------------------
    
    

    persona.h

    -------------------------------------------------------------
    #ifndef PERSONA_H
    #define PERSONA_H
    
    #include <QObject>
    
    class Persona : public QObject
    {
        Q_OBJECT
    public:
        explicit Persona(QObject *parent = nullptr);
    
        void setNombre(const QString &nombre);
    
        void habla(const QString &palabra);
    
        friend inline QDebug operator<<(QDebug qd, Persona *p);
    
    signals:
        void hablo(QString);
    public slots:
        void escucha(const QString &palabra);
    private:
        QString m_nombre;
    };
    
    #endif // PERSONA_H
    ---------------------------------------------------
    

    persona.cpp

    #include "persona.h"
    #include <QDebug>
    
    Persona::Persona(QObject *parent) : QObject(parent)
    {
    
    }
    
    void Persona::setNombre(const QString &nombre){
        m_nombre = nombre;
    }
    
    void Persona::habla(const QString &palabra){
        qDebug() << m_nombre << "Dice " << palabra;
        emit hablo(palabra);
    }
    
    void Persona::escucha(const QString &palabra){
       qDebug() << m_nombre << "Ha escuchado" << palabra;
    }
    
    inline QDebug operator<<(QDebug qd,  Persona *p){
        return qd << "El nombre es: " << p->m_nombre;
    }
    

    problems:
    main.obj:-1: error: LNK2019: unresolved external symbol "class QDebug __cdecl operator<<(class QDebug,class Persona *)"
    debug\newoperator.exe:-1: error: LNK1120:

    Thanks

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      remove the inline from the operator since it's not inline.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      J 1 Reply Last reply
      3
      • Christian EhrlicherC Christian Ehrlicher

        remove the inline from the operator since it's not inline.

        J Offline
        J Offline
        JonexElectronic
        wrote on last edited by
        #3

        @Christian-Ehrlicher 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