Illegal call of non-static member function!
-
Hey! I am Burhan
I am working on a periodic table in Qt c++.
The theme is when you click on the button of an element the properties of the respective element appears in the dialog.
Before working on the periodic table and design all buttons i want to test a one first.
While designing the dialog of a button i met some error see this dialog code.
@#include "dialog.h"
#include "ui_dialog.h"
#include<QLabel>
#include <QtGui>
#include <QtCore>Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{ui->setupUi(this); Dialog::information();
}
void information (void)
{
QGridLayout *layout = new QGridLayout;
QLabel *Name = new QLabel("Name");
layout->addWidget(Name,0,0);QLabel *Symbol" = new QLabel("Symbol"); layout->addWidget(Symbol",1,0); QLabel *Atomic= new QLabel("Atomic mass"); layout->addWidget(Atomic,2,0); QLabel *Number= new QLabel("Atomic Number"); layout->addWidget(Number,3,0); Dialog::setLayout(layout);// error: C2352: 'QWidget::setLayout' : illegal call of non-static member function // qwidget.h:546: see declaration of 'QWidget::setLayout' Dialog::show();//error: C2352: 'QWidget::show' : illegal call of non-static member function //qwidget.h:487: see declaration of 'QWidget::show'
}
Dialog::~Dialog()
{
delete ui;
}
@
I want to make a function "information" which contains all the information of element. but when i make a function it shows me some error (mentioned abv)...
Thanks in advance..
Sorry for the bad english. -
Also if anybody can tell the method.. how to make a general function of information & how to call it in other dialog of different element, so that i can use it in each dialog of respective elements.
i am beginner. Will highly be thankful. -
Your method information is not implemented as a member function.
Change
@
void information (void)
{
QGridLayout *layout = new QGridLayout;
QLabel *Name = new QLabel("Name");
@to
@
void Dialog :: information (void)
{
QGridLayout *layout = new QGridLayout;
QLabel *Name = new QLabel("Name");
@ -
Ahan i got it :)
Thanks Alot Koahnig! Thanks in tons.I will appreciate, if you can guide me about how to use this function in all dialogs?
means, i want to create a class of this function so that i can use in every dialog because my information method is same for all the dialog.
Thanks again. -
It is not clear to me why you need to do the same thing in different dialog classes.
Isn't it good enough to have several instances of the dialog class for your purpose?