Sending a message to a Telegram bot
-
@JonB said in Sending a message to a Telegram bot:
@jenya7 said in Sending a message to a Telegram bot:
extern telebot m_telebot; works pretty well.
Until that module links with something which does not define a global
telebot m_telebot
, and then it falls over. Every module you write relies on yourmain.cpp
defining it, not good. Again, if you want to write code where modules useextern
to reference something without getting it from the appropriate header file that is up to you.I'm loosing you.
module.h
extern MY_CLASS m_my_class;
module.cpp
MY_CLASS m_my_class;
another_module.cpp
#include "module.h" m_my_class.Method_1();
How do you think a static class works? Not the same way?
@jenya7
This is "fine", insofar as you have changed the example to some othermodule.cpp
/.h
. But your code fortelebot m_telebot;
I thought was inmain.cpp
, and that would require includingmain.h
elsewhere. I now think did not mean it was inmain
, that was not clear to me.While you choose to use a global variable, you already previously discovered (with your
sys_params
andTelegramBot
) that you have no opportunity to do anything initialisation-wise prior to its construction, which your code came a cropper on, you didn't understand and you had to work around. Same could happen with destructor. (You may or may not be aware, but additionally you can have aQString
member (like yourSYS_PARAMS sys_params
) but you cannot have anyQObject
-derived members for such a class if you wanted them.) But it didn't put you off, so up to you.