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. Use MainWindow ui in another class?
Forum Updated to NodeBB v4.3 + New Features

Use MainWindow ui in another class?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 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.
  • P Offline
    P Offline
    pditty8811
    wrote on last edited by
    #1

    How do I use the ui-> property or attribute of MainWindow from another class(class called GetInfo).

    Here is the function I want to move to another class:

    @void MainWindow::grabDate(){

    ui->lblDateChange->setText("August 5, 1940");
    

    }@

    I'd like to move it to another class called GetInfo. So I would think it would look like this:

    @void GetInfo::grabDate(){

    ui->lblDateChange->setText("August 5, 1940");
    

    }@

    Its a simple label that I change the text of. I launch it within MainWindow with grabData();

    Also, how do you create an object of MainWindow class in another class? Is that even possible.

    Can I do this to create object of MainWindow in GetInfo class?:

    @MainWindow objMainWindow;@
    or
    @
    MainWindow objMainWindow = new MainWindow;
    @
    Please help.
    Thanks.

    1 Reply Last reply
    1
    • N Offline
      N Offline
      NicuPopescu
      wrote on last edited by
      #2

      I don't know what is your purpose but I can guess you look for a rapid way to create widgets in your application; then you would not want to touch the Ui::MainWindow as it should manage your ui logic, I mean it should remain created in main.cpp; for widgets creation by designer just add other designer's form providing code for creating widgets having a QWidget's parent

      anyway, regarding your code:

      bq. Can I do this to create object of MainWindow in GetInfo class?:

      MainWindow objMainWindow;

      this is enough to create a QMainWindow object in your class but since ui is created in MainWindows class's constructor:

      @MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)@

      and is private, you need a public getter for it in MainWindow

      hope this help! :)

      Cheers!

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pditty8811
        wrote on last edited by
        #3

        [quote author="NicuPopescu" date="1381488511"]

        this is enough to create a QMainWindow object in your class but since ui is created in MainWindows class's constructor:

        @MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)@

        and is private, you need a public getter for it in MainWindow

        hope this help! :)

        Cheers![/quote]

        What is a public getter?

        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