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->addWidget(men);
qs->setCurrentIndex(0);
}
mainwindow::functions1()
{
std::cout<<"function called";
}
#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";
}
To copy to clipboard, switch view to plain text mode
Here is the code of the child widget.
menu1.cpp
{
resize(880,558);
}
menu1::menu1(QWidget *parent) :
QWidget(parent)
{
resize(880,558);
}
To copy to clipboard, switch view to plain text mode
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,
Bookmarks