QXmpp doesn't connect to server when button clicked
-
When I try to connect to my server via the main method, the connection succeeds. However when I try to do this via the push of a button in a separate class, the connection ends at "Sat Sep 18 20:02:39 2021 INFO Connecting to localhost:4999"
Here a snippet of the main class:
int main(int argc, char *argv[]) { QApplication a(argc, argv); QXmppConfiguration configuration; configuration.setDomain("siya"); configuration.setPort(4999); configuration.setJid("siya@siya"); configuration.setPassword("siya"); configuration.setHost("localhost"); configuration.setUser("siya"); Client client(configuration); client.logger()->setLoggingType(QXmppLogger::StdoutLogging); client.connectToServer(configuration); MainWindow w; w.show(); return a.exec(); }
And here is a snippet of the method which should connect to the server:
void MainWindow::connected() { QXmppConfiguration configuration; configuration.setDomain("siya"); configuration.setPort(4999); configuration.setJid("siya@siya"); configuration.setPassword("siya"); configuration.setHost("localhost"); configuration.setUser("siya"); Client client(configuration); client.logger()->setLoggingType(QXmppLogger::StdoutLogging); qDebug() << "here"; client.connectToServer(configuration); }
The naming of the method is a bit off but.
Naturally, I comment out the one way to connect before trying the other. I believe I have also set up the signals correctly as when I press the button, there is output indicating a connection was attempted to be established. The "network" property is also included in the .pro file. I'm not sure what's going wrong.
EDIT: Just for clarification, the Client class inherits the QXmppClient class. Even when I tried using the QXmppClient class directly, I got the same issue.
-
@siya said in QXmpp doesn't connect to server when button clicked:
Client client(configuration);
Basic c++ knowledge missing - how long does this object live?
-
@Christian-Ehrlicher oops. Allocated from heap, now works properly - thanks. Didn't know this was "basic" c++ knowledge though, but alright
-
@siya said in QXmpp doesn't connect to server when button clicked:
Allocated from heap
Would be easier to simply make client class member - no need to allocate on the heap (and delete later when not needed anymore).