can't emit a signal from a class, error: LNK2019: unresolved external symbol
-
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)
-
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.
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. -
@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)?
-
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.@solidtyper signals and slots are instance dependent in connect. You do not make them static.
-
@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)?
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