Results 1 to 8 of 8

Thread: Access Signal of Class Member Variable

  1. #1
    Join Date
    Oct 2011
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Access Signal of Class Member Variable

    I have a subclass of QMainWindow that includes a QProgressBar as a member. The subclass also contains an instance of another class called articlePage, which contains a QWebView. I want to connect the loadProgress signal of the QWebView to the setValue slot of the progress bar.

    Qt Code:
    1. class articlePage;
    2.  
    3. class appWindow : public QMainWindow
    4. {
    5. Q_OBJECT
    6.  
    7. public:
    8. appWindow(QWidget* parent = 0);
    9.  
    10. private:
    11. articlePage *firstPage;
    12. QProgressBar *webLoad;
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. class articlePage : public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. articlePage(QWidget* parent=0);
    7. QWebView *wordSearch;
    To copy to clipboard, switch view to plain text mode 

    Placing
    Qt Code:
    1. connect(firstPage->wordSearch, SIGNAL(loadProgress(int)), webLoad, SLOT(setValue(int)));
    To copy to clipboard, switch view to plain text mode 

    in appWindow.cpp gives a segmentation fault. What is the proper way to access wordSearch's signals?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Access Signal of Class Member Variable

    What is the proper way to access wordSearch's signals?
    Like you have, but the objects must exist before you can do this. Segmentation faults are, more often than not, the result of using an uninitialised or invalid pointer.

  3. #3
    Join Date
    Oct 2011
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Access Signal of Class Member Variable

    Quote Originally Posted by ChrisW67 View Post
    Like you have, but the objects must exist before you can do this. Segmentation faults are, more often than not, the result of using an uninitialised or invalid pointer.
    I put the connect statement after I declared
    Qt Code:
    1. firstPage = new articlePage;
    2. webLoad = new QProgressBar;
    To copy to clipboard, switch view to plain text mode 
    in appwindow.cpp. Is that what you mean?

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Access Signal of Class Member Variable

    Yes. Presumably you were already creating the objects in your appWindow constructor to go in your UI anyway.

  5. #5
    Join Date
    Oct 2011
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Access Signal of Class Member Variable

    That still leaves me with an unexplained seg fault. I get this every time I try to access a cross-class signal.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Access Signal of Class Member Variable

    Signals are sent between objects (instances of classes) not classes.

    We cannot explain your unexplained seg fault because we have absolutely no information to go on. What does the backtrace tell you in your debugger? Read from the top down until the first line of your code. At this line you are probably using an invalid pointer.

  7. #7
    Join Date
    Oct 2011
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Access Signal of Class Member Variable

    Yes, I am trying to access signals of objects, not classes. I instantiate all classes before trying to use their members' signals.

    I don't understand what debugger you are referring to. I'm not using an IDE.

    Edit: duh, I guess I could just open the whole project in Qt Creator.
    Last edited by starkid; 18th October 2011 at 23:53. Reason: Duh

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Access Signal of Class Member Variable

    Or run a debug version of the executable in GNU gdb or Microsoft's debugger (CDB?) depending on how you build. No IDE required, but no nice GUI buttons to drive it either.

Similar Threads

  1. Replies: 3
    Last Post: 12th April 2011, 10:58
  2. Replies: 4
    Last Post: 29th May 2010, 12:56
  3. Replies: 22
    Last Post: 8th October 2008, 13:54
  4. Replies: 5
    Last Post: 14th July 2006, 22:42
  5. Std iterator as private member variable
    By Michiel in forum General Programming
    Replies: 5
    Last Post: 21st April 2006, 15:27

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.