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. Accessing gui from other class
Forum Updated to NodeBB v4.3 + New Features

Accessing gui from other class

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.2k Views 2 Watching
  • 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.
  • V Offline
    V Offline
    Veve
    wrote on last edited by
    #1

    My main class is "socketserver1" and i try to access it's gui from "MyServer" class. I created a signal on MyServer class: http://pastebin.com/u0aw9c2C . And to my socketserver1(mainwindow) i added a slot to add log: http://pastebin.com/J1XSmdhi . On my socketserver1 i added a connect to connect signal from server to slot from my socketserver1: http://pastebin.com/x8FnFrKh . However, when on second class i do "emit addToLog("ABCDEF"); it doesn't fire the slot and nothing happens.

    V 1 Reply Last reply
    0
    • V Veve

      My main class is "socketserver1" and i try to access it's gui from "MyServer" class. I created a signal on MyServer class: http://pastebin.com/u0aw9c2C . And to my socketserver1(mainwindow) i added a slot to add log: http://pastebin.com/J1XSmdhi . On my socketserver1 i added a connect to connect signal from server to slot from my socketserver1: http://pastebin.com/x8FnFrKh . However, when on second class i do "emit addToLog("ABCDEF"); it doesn't fire the slot and nothing happens.

      V Offline
      V Offline
      Veve
      wrote on last edited by
      #2

      anyone? i need to fix this

      1 Reply Last reply
      0
      • Paul H.P Offline
        Paul H.P Offline
        Paul H.
        wrote on last edited by
        #3

        Are you emitting the signal after you make the connection? If you are testing by emitting the signal in MyServer constructor, the connection will not have been made yet.
        Paul

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Veve
          wrote on last edited by Veve
          #4

          @Paul-H. i am emitting the signal when the server can list on port, so it will add to the consolelog that listening on that port started. I also will add to add to consolelog when incommingConnection is emitted. But whenever i emit the signal, it just doesn't put anything on the ConsoleLog. The connection is made in main thread, before the server starts. Even if i put to start the serveron push of a button (so i connect it before) it doesn't fire the slot.

          1 Reply Last reply
          0
          • Paul H.P Offline
            Paul H.P Offline
            Paul H.
            wrote on last edited by Paul H.
            #5

            Ok, I apparently don't understand everything that is going on in your program.
            But if I create a bare bones QObject MyServer class as follows:

            #include "myserver.h"
            
            MyServer::MyServer(QObject *parent) : QObject(parent)
            {
            
            }
            
            void MyServer::emitTest(const QString toadd)
            {
                emit addToLog(toadd);
            }
            

            Then add a call to emitTest in the socketserver1 class after the connect:

                MyServer *server = new MyServer(this);
                connect(server,SIGNAL(addToLog(const QString)),this,SLOT(addLog(const QString)));
                server->emitTest("TEST1");
            

            the slot is fired as expected. That is why I thought that the signal was being emitted before it was connected to the slot.
            Paul

            Edit: You mention using threads, which I am not experienced with. Does it make a difference if you make the MyServer *server a member variable of socketserver1 class instead of declaring it locally in the constructor?

            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