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. Qt general issue accessing a member of another class
Forum Updated to NodeBB v4.3 + New Features

Qt general issue accessing a member of another class

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 1.7k 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.
  • S Offline
    S Offline
    stuyfozz
    wrote on last edited by
    #1

    Hi,
    I'm trying to access a member of a different class i.e. (i have took out all other code due to it being unrelated to my issue)

    header1.h

    @class MainWindow : public QMainWindow
    {
    public:
    MainWindow();

    public slots:
    int open();
    };
    @
    header2.h

    @class SaveWindow : public QTextEdit
    {
    public:
    SaveWindow();

    public slots:
    int save();
    };
    @
    mainWindow.cpp

    @#include "header1.h"
    #include "header2.h"

    int MainWindow::open()
    {
    BLAAA...
    return save();
    ^^^^^^^^^^^^^^^wont let me access save, due to being MainWindow::open and save is not a member of that class! Tried creating an object and trying to access through that but no joy!
    }

    int SaveWindow::save()
    {
    BLAAA...
    }
    @
    There is probably a simple solution.

    doing....
    @
    SaveWindow sw;
    return sw.save();
    @
    also gives me errors.
    Thanks for any help :)

    Edit: added some @ tags to your post to format your code; Andre

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hostel
      wrote on last edited by
      #2

      Please put your code in @ @ (without ) block.

      This should work.
      @
      SaveWindow sw;
      return sw.save();
      @

      But this code doesn't work:
      @
      int MainWindow::open()
      {
      BLAAA…
      return save();
      }
      @
      because MainWindow hasn't a save method.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stuyfozz
        wrote on last edited by
        #3

        Hi,
        I'm confused, trying to access a member of a different class i.e.

        header1.h

        @class MainWindow : public QMainWindow
        {
        public:
        MainWindow();

        public slots:
        int Open();
        };@

        header2.h

        @class SaveWindow : public QTextEdit
        {
        public:
        SaveWindow();

        public slots:
        int Save();
        };@

        mainWindow.cpp

        @#include "header1.h"
        #include "header2.h"

        int MainWindow::Open()
        {
        BLAAA...
        return Save();
        ////////////////////////////////////////////////////<<<<<<<<<<wont let me access Save, due to being MainWindow::Open and Save is not a member of that class! Tried creating an object and trying to access through that but no joy!
        }

        int SaveWindow::Save()
        {
        BLAAA...
        }@

        Sorry I'm new to Qt and posting

        1 Reply Last reply
        0
        • H Offline
          H Offline
          Hostel
          wrote on last edited by
          #4

          Read about some course or book about C++ because you issue is with language, not Qt. If you will had a basic skills with C++ then would be a sense to help you with your code. I think that now you are typing code in blind without understanding.

          1 Reply Last reply
          0
          • JeroentjehomeJ Offline
            JeroentjehomeJ Offline
            Jeroentjehome
            wrote on last edited by
            #5

            What should work is when you create a variable of the SaveWindow class and call that function.
            @
            int MainWindow::Open(void)
            {
            BLAA...
            SaveWindow saveThing;
            return saveThing.save();
            @
            if that works for you. The saveWindow will be destroyed when the open function quits, so don't worry about that.

            Greetz, Jeroen

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tzander
              wrote on last edited by
              #6

              Posting some code that will likely work is good, but in this case I think I agree more with Hostel since you really need to get your basic "Object Oriented" concepts clear. Otherwise its going to be too frustrated to do anything :)

              So I hope that stuyfozz didn't totally got scare off and is busy reading some basic Object Oriented and C++ tutorials :)

              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