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. can't emit a signal from a class, error: LNK2019: unresolved external symbol

can't emit a signal from a class, error: LNK2019: unresolved external symbol

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 753 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.
  • S Offline
    S Offline
    solidtyper
    wrote on last edited by solidtyper
    #1

    i've created this class in VS2019 console app, but now i'm using my code in QT(UI app).

    ---General.h

    #pragma once
    
    #ifndef GENERAL_H
    #define GENERAL_H
    #define WIN32_LEAN_AND_MEAN
    
    #include <string>
    #include <iostream>
    #include <Windows.h>
    #include "server.h"
    
    #include <QObject>
    #include <QDebug>
    
    class General : public QObject
    {
        Q_OBJECT
    
    signals:
        static void logSig();
    
    public:	//functions
        static void outputMsg(std::string message, int msgType);
        static bool processParameter(std::string &command, std::string compCommand);
    
    public:	//variables
        static bool cmdMode;
        static void log();
    };
    
    #endif // !GENERAL_H
    
    

    and here is General.cpp

    #include "general.h"
    
    bool General::cmdMode = false;
    
    void General::outputMsg(std::string message, int msgType)
    {
       //when i remove this line it works
        emit General::logSig();
    }
    

    ERR: general.obj:-1: error: LNK2019: unresolved external symbol "public: static void __cdecl General::logSig(void)" (?logSig@General@@SAXXZ) referenced in function "public: static void __cdecl General::outputMsg(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int)" (?outputMsg@General@@SAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z)

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mchinand
      wrote on last edited by
      #2

      Do you connect that signal to a slot elsewhere in your code? What does your connect statement look like? Specifically, what is your 'sender' object? I think it's unusual to have a signal be static.

      S 1 Reply Last reply
      0
      • M mchinand

        Do you connect that signal to a slot elsewhere in your code? What does your connect statement look like? Specifically, what is your 'sender' object? I think it's unusual to have a signal be static.

        S Offline
        S Offline
        solidtyper
        wrote on last edited by solidtyper
        #3

        @mchinand

        i've worked with signals in this code in many times, you can emit a signal without connecting it and it doesn't throw this error.

        i juts made it static so i can call it like this emit General::sig();, because the method i call it from is static.

        this is how i connect it in Server.cpp:

        General* general = new General();
        QObject::connect(general, &General::sig, this, &Server::slot);

        i removed static and called it from a non-static method. but nothing...

        i guess i'll need to remake this class in Qt since even when i try to General* general = new General(); make a pointer to it it throws a similar error.

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

          @solidtyper said in can't emit a signal from a class, error: LNK2019: unresolved external symbol:

          VS2019 console app

          I'm not sure what you mean by this, but have you run moc on this file (or more likely, have it run automatically if you have a Qt .pro file or CMakeLists.txt file)?

          S 1 Reply Last reply
          0
          • S solidtyper

            @mchinand

            i've worked with signals in this code in many times, you can emit a signal without connecting it and it doesn't throw this error.

            i juts made it static so i can call it like this emit General::sig();, because the method i call it from is static.

            this is how i connect it in Server.cpp:

            General* general = new General();
            QObject::connect(general, &General::sig, this, &Server::slot);

            i removed static and called it from a non-static method. but nothing...

            i guess i'll need to remake this class in Qt since even when i try to General* general = new General(); make a pointer to it it throws a similar error.

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by JoeCFD
            #5

            @solidtyper signals and slots are instance dependent in connect. You do not make them static.

            1 Reply Last reply
            1
            • M mchinand

              @solidtyper said in can't emit a signal from a class, error: LNK2019: unresolved external symbol:

              VS2019 console app

              I'm not sure what you mean by this, but have you run moc on this file (or more likely, have it run automatically if you have a Qt .pro file or CMakeLists.txt file)?

              S Offline
              S Offline
              solidtyper
              wrote on last edited by
              #6

              @mchinand

              what i meant is that it might have something under the hood, IDK but it's acting very different. but i'm noob at this i might be wrong.

              anyhow. i deleted that class definetly and add the properties directly to the thread i tried to send the signal to.

              it was only for categorizing methods, nothting else.

              thank you BTW

              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