el33t
15th March 2011, 20:33
I want to access a function in my parent from a child widget.
This is the code of the parent widget:
mainwindow.cpp
#include <QtGui>
#include <iostream>
#include "mainwindow.h"
#include "menu1.h"
mainwindow::mainwindow()
{
men = new menu1(this); // This is the child widget
qs = new QStackedWidget(this);
qs->addWidget(men);
qs->setCurrentIndex(0);
}
mainwindow::functions1()
{
std::cout<<"function called";
}
Here is the code of the child widget.
menu1.cpp
menu1::menu1(QWidget *parent) :
QWidget(parent)
{
resize(880,558);
}
Now, I want to access funtion1 from 'men'. How do I do it?
I tried the following in men.cpp but got errors:
1) parent->funtion1();
This gives the error: 'class Qwidget' has no member named 'funtion1'
2) parent->parent->funtion1();
This gave the error : invalid use of member (did you forget the '&')
base operand of '->' is not a pointer
Any help would be appreciated.
Regards,
This is the code of the parent widget:
mainwindow.cpp
#include <QtGui>
#include <iostream>
#include "mainwindow.h"
#include "menu1.h"
mainwindow::mainwindow()
{
men = new menu1(this); // This is the child widget
qs = new QStackedWidget(this);
qs->addWidget(men);
qs->setCurrentIndex(0);
}
mainwindow::functions1()
{
std::cout<<"function called";
}
Here is the code of the child widget.
menu1.cpp
menu1::menu1(QWidget *parent) :
QWidget(parent)
{
resize(880,558);
}
Now, I want to access funtion1 from 'men'. How do I do it?
I tried the following in men.cpp but got errors:
1) parent->funtion1();
This gives the error: 'class Qwidget' has no member named 'funtion1'
2) parent->parent->funtion1();
This gave the error : invalid use of member (did you forget the '&')
base operand of '->' is not a pointer
Any help would be appreciated.
Regards,