PDA

View Full Version : Access Signal of Class Member Variable



starkid
17th October 2011, 22:40
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.



class articlePage;

class appWindow : public QMainWindow
{
Q_OBJECT

public:
appWindow(QWidget* parent = 0);

private:
articlePage *firstPage;
QProgressBar *webLoad;



class articlePage : public QWidget
{
Q_OBJECT

public:
articlePage(QWidget* parent=0);
QWebView *wordSearch;


Placing

connect(firstPage->wordSearch, SIGNAL(loadProgress(int)), webLoad, SLOT(setValue(int)));

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

ChrisW67
17th October 2011, 22:45
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.

starkid
17th October 2011, 22:47
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

firstPage = new articlePage;
webLoad = new QProgressBar;
in appwindow.cpp. Is that what you mean?

ChrisW67
17th October 2011, 23:12
Yes. Presumably you were already creating the objects in your appWindow constructor to go in your UI anyway.

starkid
18th October 2011, 13:55
That still leaves me with an unexplained seg fault. I get this every time I try to access a cross-class signal.

ChrisW67
18th October 2011, 23:40
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.

starkid
18th October 2011, 23:50
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.

ChrisW67
19th October 2011, 00:19
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.