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. QXmpp doesn't connect to server when button clicked
Forum Updated to NodeBB v4.3 + New Features

QXmpp doesn't connect to server when button clicked

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 308 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
    siya
    wrote on last edited by siya
    #1

    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.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      S 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @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?

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

        @Christian-Ehrlicher oops. Allocated from heap, now works properly - thanks. Didn't know this was "basic" c++ knowledge though, but alright

        jsulmJ 1 Reply Last reply
        0
        • S siya

          @Christian-Ehrlicher oops. Allocated from heap, now works properly - thanks. Didn't know this was "basic" c++ knowledge though, but alright

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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).

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          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