Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Illegal call of non-static member function!
Forum Updated to NodeBB v4.3 + New Features

Illegal call of non-static member function!

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 8.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    buxi07
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      buxi07
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        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");
        @

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • B Offline
          B Offline
          buxi07
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            koahnig
            wrote on last edited by
            #5

            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?

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved