Results 1 to 9 of 9

Thread: Accessing GUI widget from different class

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Posts
    1,241
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3
    Thanked 127 Times in 126 Posts

    Default Re: Accessing GUI widget from different class

    Off topic, but Op has circular reference => design error.

    Main window composed of sslserver, and sslserver impl also needs full knowledge of MainWindow.

    edit:
    I think that main window code in your sslserver is just you being a bit confused. You want to be updating the existing mainwin nit creating a new one. So there you should emit a signal with the new count as an argument. Connect that signal to a slot on your mainwin, and from there you can update the label text
    Last edited by amleto; 4th December 2012 at 21:52.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  2. #2
    Join Date
    Sep 2012
    Posts
    34
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Re: Accessing GUI widget from different class

    Quote Originally Posted by amleto View Post
    Off topic, but Op has circular reference => design error.

    Main window composed of sslserver, and sslserver impl also needs full knowledge of MainWindow.

    edit:
    I think that main window code in your sslserver is just you being a bit confused. You want to be updating the existing mainwin nit creating a new one. So there you should emit a signal with the new count as an argument. Connect that signal to a slot on your mainwin, and from there you can update the label text
    Thanks, I see your point. I already tried SIGNAL-SLOT solution, but I guess I had some error on it. I'll give it another try and get back with the result.

    I think I should add following to the sslserver.c:

    Qt Code:
    1. connect(thread, SIGNAL(finished()), main, SLOT(count_update()));
    To copy to clipboard, switch view to plain text mode 

    I'm not sure though what I should put to the third parameter? Certainly main is not correct. I think this was the problem I faced when I tried to use the SIGNALs for this issue.

    Cheers!

  3. #3
    Join Date
    Sep 2011
    Posts
    1,241
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3
    Thanked 127 Times in 126 Posts

    Default Re: Accessing GUI widget from different class

    sslserver should be emitting signal, therefore it should not be the one doing the connection.
    mainwindow should connect to sslserver
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  4. #4
    Join Date
    Sep 2012
    Posts
    34
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Re: Accessing GUI widget from different class

    Thank guys! I got it working. My problem was that I was not using pointer of object sslserver. With the following connection it worked out:

    Qt Code:
    1. SslServer *ptr_server = &server;
    2. connect(ptr_server, SIGNAL(count(int)), this, SLOT(update_count(int)));
    To copy to clipboard, switch view to plain text mode 

    Cheers!

  5. #5
    Join Date
    Sep 2011
    Posts
    1,241
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3
    Thanked 127 Times in 126 Posts

    Default Re: Accessing GUI widget from different class

    Qt Code:
    1. connect(&server, SIGNAL(count(int)), this, SLOT(update_count(int)));
    To copy to clipboard, switch view to plain text mode 
    that is good enough!
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. accessing static member variables of one class in another class
    By jasonknight in forum General Programming
    Replies: 5
    Last Post: 6th September 2010, 14:53
  2. Accessing a class Object by pointer in another class
    By pdoria in forum Qt Programming
    Replies: 2
    Last Post: 14th January 2008, 15:59
  3. Not accessing widget outside the class
    By santosh.kumar in forum Qt Programming
    Replies: 6
    Last Post: 18th May 2007, 12:57
  4. Accessing to a static variable from the same class
    By xgoan in forum General Programming
    Replies: 6
    Last Post: 5th March 2007, 10:50
  5. accessing my own class-instances
    By mikro in forum Newbie
    Replies: 3
    Last Post: 11th July 2006, 00:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.