Sending a message to a Telegram bot
-
@jsulm said in Sending a message to a Telegram bot:
@jenya7 Start the Qt Maintenance Tool and select OpenSSL there, install...
When I get to Setup - Qt stage I get
There is an important update available, please run the udater first
How do I run the updater?
-
@jsulm said in Sending a message to a Telegram bot:
@jenya7 Start the Qt Maintenance Tool and select OpenSSL there, install...
When I get to Setup - Qt stage I get
There is an important update available, please run the udater first
How do I run the updater?
@jenya7 said in Sending a message to a Telegram bot:
How do I run the updater?
What about clicking on "Update components" and then "Next"?
-
@jenya7 said in Sending a message to a Telegram bot:
How do I run the updater?
What about clicking on "Update components" and then "Next"?
@jsulm said in Sending a message to a Telegram bot:
@jenya7 said in Sending a message to a Telegram bot:
How do I run the updater?
What about clicking on "Update components" and then "Next"?
Thank you. Now it's OK, OpenSSL installed, added LIBS += C:/Qt/Tools/OpenSSL/Win_x64/lib/libssl.lib
But still the same problem - [99] TLS initialization failedwell...in a Linux project I don't have this problem. probably openssl installed and handled properly in Linux.
But when I run the code
TelegramBot bot("my_api_key"); bot.sendMessage("my_chat_id", "This is a test");
I get in Debug window
QUrl("https://api.telegram.org/botmy_api_key/sendMessage?chat_id=my_chat_id&text=This is a test")
And nothing happens - my bot did not get the message.well...I've managed to send and get a message on Linux. actually it's good enough, my project should run on Linux.
-
Hi,
I would guess that your application cannot find the dlls at run time. You need to add the path to these to the PATH environment variable. Do that in the Run part of the Project panel.
-
Hi,
I would guess that your application cannot find the dlls at run time. You need to add the path to these to the PATH environment variable. Do that in the Run part of the Project panel.
@SGaist said in Sending a message to a Telegram bot:
Hi,
I would guess that your application cannot find the dlls at run time. You need to add the path to these to the PATH environment variable. Do that in the Run part of the Project panel.
I did so
still the same problem - [99] TLS initialization failed
-
@SGaist said in Sending a message to a Telegram bot:
Hi,
I would guess that your application cannot find the dlls at run time. You need to add the path to these to the PATH environment variable. Do that in the Run part of the Project panel.
I did so
still the same problem - [99] TLS initialization failed
-
@jsulm said in Sending a message to a Telegram bot:
@jenya7 You need to add the path to the FOLDER containing the libs without the file name!
OK. Did so. Removed the name. Still the same problem.
-
@jsulm said in Sending a message to a Telegram bot:
@jenya7 Does that folder also contain the dll file?
I ran a search in Qt folder on any ssl related files and found only
ssleay32.dll in C:\Qt\Tools\mingw730_64\opt\bin and C:\Qt\Tools\QtCreator\bin
Should I include the paths too? -
I have a problem.
This way it works - if I initialize explicitly with a stringtelebot::telebot(QObject *parent) : QObject(parent) { TelegramBot bot("my_api_key"); QObject::connect(&bot, &TelegramBot::newMessage, this, &telebot::NewMessage); }
But if I do it with variable
telebot::telebot(QObject *parent) : QObject(parent) { if (!sys_params.bot_api_key.isNull() && !sys_params.bot_api_key.isEmpty()) { TelegramBot bot(sys_params.bot_api_key); QObject::connect(&bot, &TelegramBot::newMessage, this, &telebot::NewMessage); } }
I get the error
The inferior stopped because it received a signal from the operating system.
Signal name : SIGSEGV
Signal meaning : Segmentation faultI see the constructor works before sys_params initialization although I set first line after window activation
int main(int argc, char *argv[]) { QFuture<uint32_t> discovered; QApplication a(argc, argv); MainWindow w; w.show(); //here is sys_params initialization SetupRun(); //some other code return a.exec(); }
What should I do?
-
I have a problem.
This way it works - if I initialize explicitly with a stringtelebot::telebot(QObject *parent) : QObject(parent) { TelegramBot bot("my_api_key"); QObject::connect(&bot, &TelegramBot::newMessage, this, &telebot::NewMessage); }
But if I do it with variable
telebot::telebot(QObject *parent) : QObject(parent) { if (!sys_params.bot_api_key.isNull() && !sys_params.bot_api_key.isEmpty()) { TelegramBot bot(sys_params.bot_api_key); QObject::connect(&bot, &TelegramBot::newMessage, this, &telebot::NewMessage); } }
I get the error
The inferior stopped because it received a signal from the operating system.
Signal name : SIGSEGV
Signal meaning : Segmentation faultI see the constructor works before sys_params initialization although I set first line after window activation
int main(int argc, char *argv[]) { QFuture<uint32_t> discovered; QApplication a(argc, argv); MainWindow w; w.show(); //here is sys_params initialization SetupRun(); //some other code return a.exec(); }
What should I do?
@jenya7 said in Sending a message to a Telegram bot:
Signal name : SIGSEGV
What should I do?
You are supposed to run your code in a debugger. It will stop on the seg fault, go to the stack trace window to see information about where this is occurring from your code/the code you call.
Since we have no idea what your
sys_params.bot_api_key
is or what is in it, and since you say introducing it causes a seg fault, that would be my first suspect.....telebot::telebot(QObject *parent) : QObject(parent) { TelegramBot bot("my_api_key"); QObject::connect(&bot, &TelegramBot::newMessage, this, &telebot::NewMessage); }
Your
TelegramBot bot
is a local variable, it will go out of scope and be destroyed at the end of this constructor. Same applies in your second code attempt. What do you think you are achieving with this code, because it is not right. -
@jenya7 said in Sending a message to a Telegram bot:
Signal name : SIGSEGV
What should I do?
You are supposed to run your code in a debugger. It will stop on the seg fault, go to the stack trace window to see information about where this is occurring from your code/the code you call.
Since we have no idea what your
sys_params.bot_api_key
is or what is in it, and since you say introducing it causes a seg fault, that would be my first suspect.....telebot::telebot(QObject *parent) : QObject(parent) { TelegramBot bot("my_api_key"); QObject::connect(&bot, &TelegramBot::newMessage, this, &telebot::NewMessage); }
Your
TelegramBot bot
is a local variable, it will go out of scope and be destroyed at the end of this constructor. Same applies in your second code attempt. What do you think you are achieving with this code, because it is not right.@JonB said in Sending a message to a Telegram bot:
@jenya7 said in Sending a message to a Telegram bot:
Signal name : SIGSEGV
What should I do?
You are supposed to run your code in a debugger. It will stop on the seg fault, go to the stack trace window to see information about where this is occurring from your code/the code you call.
Since we have no idea what your
sys_params.bot_api_key
is or what is in it, and since you say introducing it causes a seg fault, that would be my first suspect.....telebot::telebot(QObject *parent) : QObject(parent) { TelegramBot bot("my_api_key"); QObject::connect(&bot, &TelegramBot::newMessage, this, &telebot::NewMessage); }
Your
TelegramBot bot
is a local variable, it will go out of scope and be destroyed at the end of this constructor. Same applies in your second code attempt. What do you think you are achieving with this code, because it is not right.Yes I stop with a breakpoint at
if (!sys_params.bot_api_key.isNull() && !sys_params.bot_api_key.isEmpty())
the next step - refering to sys_params.bot_api_key generates the error.It's a field of a structure
typedef struct { //some fields QString bot_api_key; }SYS_PARAMS; SYS_PARAMS sys_params;
How can I do it global? It's not like I can instantiate it
TelegramBot bot; telebot::telebot(QObject *parent) : QObject(parent) { bot = new TelegramBot ("my_api_key"); //is not allowed }
-
@JonB said in Sending a message to a Telegram bot:
@jenya7 said in Sending a message to a Telegram bot:
Signal name : SIGSEGV
What should I do?
You are supposed to run your code in a debugger. It will stop on the seg fault, go to the stack trace window to see information about where this is occurring from your code/the code you call.
Since we have no idea what your
sys_params.bot_api_key
is or what is in it, and since you say introducing it causes a seg fault, that would be my first suspect.....telebot::telebot(QObject *parent) : QObject(parent) { TelegramBot bot("my_api_key"); QObject::connect(&bot, &TelegramBot::newMessage, this, &telebot::NewMessage); }
Your
TelegramBot bot
is a local variable, it will go out of scope and be destroyed at the end of this constructor. Same applies in your second code attempt. What do you think you are achieving with this code, because it is not right.Yes I stop with a breakpoint at
if (!sys_params.bot_api_key.isNull() && !sys_params.bot_api_key.isEmpty())
the next step - refering to sys_params.bot_api_key generates the error.It's a field of a structure
typedef struct { //some fields QString bot_api_key; }SYS_PARAMS; SYS_PARAMS sys_params;
How can I do it global? It's not like I can instantiate it
TelegramBot bot; telebot::telebot(QObject *parent) : QObject(parent) { bot = new TelegramBot ("my_api_key"); //is not allowed }
@jenya7 said in Sending a message to a Telegram bot:
the next step - refering to sys_params.bot_api_key generates the error
As @JonB asked: how does the stack trace look like after crash?
"How can I do it global?" - why should it be global? Simply make bot a class member...
-
@JonB said in Sending a message to a Telegram bot:
@jenya7 said in Sending a message to a Telegram bot:
Signal name : SIGSEGV
What should I do?
You are supposed to run your code in a debugger. It will stop on the seg fault, go to the stack trace window to see information about where this is occurring from your code/the code you call.
Since we have no idea what your
sys_params.bot_api_key
is or what is in it, and since you say introducing it causes a seg fault, that would be my first suspect.....telebot::telebot(QObject *parent) : QObject(parent) { TelegramBot bot("my_api_key"); QObject::connect(&bot, &TelegramBot::newMessage, this, &telebot::NewMessage); }
Your
TelegramBot bot
is a local variable, it will go out of scope and be destroyed at the end of this constructor. Same applies in your second code attempt. What do you think you are achieving with this code, because it is not right.Yes I stop with a breakpoint at
if (!sys_params.bot_api_key.isNull() && !sys_params.bot_api_key.isEmpty())
the next step - refering to sys_params.bot_api_key generates the error.It's a field of a structure
typedef struct { //some fields QString bot_api_key; }SYS_PARAMS; SYS_PARAMS sys_params;
How can I do it global? It's not like I can instantiate it
TelegramBot bot; telebot::telebot(QObject *parent) : QObject(parent) { bot = new TelegramBot ("my_api_key"); //is not allowed }
-
@jenya7 said in Sending a message to a Telegram bot:
the next step - refering to sys_params.bot_api_key generates the error
As @JonB asked: how does the stack trace look like after crash?
"How can I do it global?" - why should it be global? Simply make bot a class member...
@jsulm said in Sending a message to a Telegram bot:
@jenya7 said in Sending a message to a Telegram bot:
the next step - refering to sys_params.bot_api_key generates the error
As @JonB asked: how does the stack trace look like after crash?
"How can I do it global?" - why should it be global? Simply make bot a class member...
It stops in qstring.h at
inline bool QString::isEmpty()
const { return d->size == 0; } -
@jsulm said in Sending a message to a Telegram bot:
@jenya7 said in Sending a message to a Telegram bot:
the next step - refering to sys_params.bot_api_key generates the error
As @JonB asked: how does the stack trace look like after crash?
"How can I do it global?" - why should it be global? Simply make bot a class member...
It stops in qstring.h at
inline bool QString::isEmpty()
const { return d->size == 0; } -
@JonB said in Sending a message to a Telegram bot:
@jenya7
As @jsulm has just written for the seg fault.TelegramBot bot; bot = new TelegramBot ("my_api_key"); //is not allowed
Why do you think this is "not allowed"? What does the compiler error message tell you, I would guess it's pretty clear?
TelegramBot bot; //here - error: no matching constructor for initialization of 'TelegramBot'
bot = new TelegramBot ("my_api_key");
-
@JonB said in Sending a message to a Telegram bot:
@jenya7
As @jsulm has just written for the seg fault.TelegramBot bot; bot = new TelegramBot ("my_api_key"); //is not allowed
Why do you think this is "not allowed"? What does the compiler error message tell you, I would guess it's pretty clear?
TelegramBot bot; //here - error: no matching constructor for initialization of 'TelegramBot'
bot = new TelegramBot ("my_api_key");
@jenya7 Please learn C++!
Your TelegramBot class has no constructor without parameter!
Also, if you want to allocate TelegramBot on the heap then bot needs to be a pointer. All these are absolute basics.TelegramBot *bot; bot = new TelegramBot ("my_api_key");
-
@jsulm said in Sending a message to a Telegram bot:
@jenya7 said in Sending a message to a Telegram bot:
the next step - refering to sys_params.bot_api_key generates the error
As @JonB asked: how does the stack trace look like after crash?
"How can I do it global?" - why should it be global? Simply make bot a class member...
It stops in qstring.h at
inline bool QString::isEmpty()
const { return d->size == 0; }@jenya7 said in Sending a message to a Telegram bot:
It stops in qstring.h at
inline bool QString::isEmpty()
const { return d->size == 0; }In addition to @jsulm's excellent points. We don't know the scope of your
sys_params
(probably "global", yuck, don't do that), and:typedef struct { //some fields QString bot_api_key; }SYS_PARAMS; SYS_PARAMS sys_params;
We don't know whether you have written anything to the "some fields", or written directly into
sys_params
. -
@jsulm said in Sending a message to a Telegram bot:
@jenya7 This not stack trace...
1 QString::isEmpty qstring.h 937 0x28bd8
2 telebot::telebot telebot.cpp 10 0x56040
3 __static_initialization_and_destruction_0 telebot.cpp
4 0x5652c 4 _GLOBAL__sub_I_telebot.cpp(void) telebot.cpp 69 0x56588
5 __libc_csu_init 0xaf61c
6 __libc_start_main libc-start.c 264 0xb5ab96ac
7 _start 0x1c5dc