need to call parent method or variable in child class.
i created parent class (QWidget)
Widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include<QtGui>
#include"secdialog.h" //child class
namespace Ui {
class Widget;
}
{
Q_OBJECT
public:
private:
Ui::Widget *ui;
secDialog *sec; //creating object to child class
public slots:
void display();
}
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include<QtGui>
#include"secdialog.h" //child class
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
QPushButton *button1;
QString list;
private:
Ui::Widget *ui;
secDialog *sec; //creating object to child class
public slots:
void display();
}
To copy to clipboard, switch view to plain text mode
secDialog.h
child class (QDialog
#ifndef SECDIALOG_H
#define SECDIALOG_H
#include <QDialog>
#include<QWidget>
#include<QtGui>
#include"widget.h"//parent class
namespace Ui {
class secDialog;
}
{
Q_OBJECT
public:
Private :
Widget *widget;//create object for parent class
public slots:
void newmethod();
}
#ifndef SECDIALOG_H
#define SECDIALOG_H
#include <QDialog>
#include<QWidget>
#include<QtGui>
#include"widget.h"//parent class
namespace Ui {
class secDialog;
}
class secDialog : public QDialog
{
Q_OBJECT
public:
Private :
Widget *widget;//create object for parent class
public slots:
void newmethod();
}
To copy to clipboard, switch view to plain text mode
Widget.cpp
#include "widget.h"
#include "ui_widget.h"
ui(new Ui::Widget)
{
button1->show();
connect(button1,SIGNAL(clicked()),this,SLOT(display());
ui->setupUi(this);
}
void Widget::display()
{
sec=new secDialog(this);
sec->show();
}
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
button1=new QPushButton("CLICK",this);
button1->show();
connect(button1,SIGNAL(clicked()),this,SLOT(display());
ui->setupUi(this);
}
void Widget::display()
{
sec=new secDialog(this);
sec->show();
}
To copy to clipboard, switch view to plain text mode
secDialog.cpp
#include "secdialog.h"
#include "ui_secdialog.h"
secDialog
::secDialog(QWidget *parent
) : ui(new Ui::secDialog)
{
newmethod();
}
void secDialog::newmethod()
{
widget->list="Hello";
qDebug<<widget->list;
}
#include "secdialog.h"
#include "ui_secdialog.h"
secDialog::secDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::secDialog)
{
newmethod();
}
void secDialog::newmethod()
{
widget=new QWidget(this);
widget->list="Hello";
qDebug<<widget->list;
}
To copy to clipboard, switch view to plain text mode
When i execute this ,i getting Error,
"widget does not name a type"
"widget does not name a type"
To copy to clipboard, switch view to plain text mode
i need to use both class variables and button,i know somewhere am doing wrong can any one help to solve this problem,
Thanks in advance
Bookmarks