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. Calling the dialog checkbox from mainwindow
Forum Update on Monday, May 27th 2025

Calling the dialog checkbox from mainwindow

Scheduled Pinned Locked Moved General and Desktop
17 Posts 2 Posters 6.5k Views
  • 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.
  • K Offline
    K Offline
    kalster
    wrote on last edited by
    #1

    In the mainwindow.cpp file i am trying to call the dialog like this uu-> but it is not working. at the dialog.cpp, i have a checkbox that i would like to call from the mainwindow.cpp. is this possible? i would like to call the dialog checkBox like this... uu->checkBox->setFocus(); from the mainwindow. the error i am getting is error: ISO C++ forbids declaration of 'MainWindow' with no type

    dialog.h
    @#ifndef DIALOG_H
    #define DIALOG_H

    #include "mainwindow.h"
    #include <QDialog>

    class MainWindow;
    namespace Ui {
    class Dialog;
    }

    class Dialog : public QDialog
    {
    Q_OBJECT

    public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();

    private:
    Ui::Dialog *ui;
    Ui::MainWindow *uu;
    };

    #endif // DIALOG_H@

    mainwindow.h
    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include "dialog.h"
    #include <QMainWindow>
    class Dialog;
    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private:
    Ui::MainWindow *ui;
    Dialog *tt;
    Ui::Dialog uu;
    };

    #endif // MAINWINDOW_H@

    dialog.cpp
    @#include "dialog.h"
    #include "ui_dialog.h"
    #include "mainwindow.h"

    Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
    {
    ui->setupUi(this);

    }

    Dialog::~Dialog()
    {
    delete ui;
    }@

    mainwindow.cpp
    @#include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "dialog.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    Dialog *uu = new Dialog(this);
    this->show();
    uu.setVisible(false);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }@

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alfah
      wrote on last edited by
      #2

      You have declared Dialog *tt in tha MainWindow.h.

      Then in the mainWindow.cpp
      jus the following is needed
      @
      tt = new Dialog(this);
      @
      right???

      is the following line needed in the dialog.h??
      @
      Ui::MainWindow *uu;
      @

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

        i am getting an error in the mainwindow error: 'class Dialog' has no member named 'checkBox'. the tt = new Dialog(this); line is for dialog methods. i need it for dialog widgets in the mainwindow.cpp file.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alfah
          wrote on last edited by
          #4

          Im not an expert :)

          u have a checkbox in your dialog.h. and it is made in the designer??

          You want to jus show that check box in the mainWindow??

          Am i right???

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

            yes. i want to call the dialog checkbox from mainwindow

            1 Reply Last reply
            0
            • A Offline
              A Offline
              alfah
              wrote on last edited by
              #6

              This displays the check box.
              The following is written in the constructor of MainWindow.cpp

              @
              ui->setupUi(this);
              Dialog *d= new Dialog();
              d->show();
              setCentralWidget(d);
              @

              alfah

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kalster
                wrote on last edited by
                #7

                not working. please verify.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  alfah
                  wrote on last edited by
                  #8

                  it is working on my device. Remember i have called the dialog class/form from the mainwindow ,if thats wat you want

                  Dialog.cpp

                  @

                  Dialog::Dialog(QWidget *parent) :
                  QDialog(parent),
                  ui(new Ui::Dialog)
                  {
                  ui->setupUi(this);
                  setLayout(ui->verticalLayout);

                  }
                  @

                  MainWindow.cpp
                  @
                  MainWindow::MainWindow(QWidget *parent) :
                  QMainWindow(parent),
                  ui(new Ui::MainWindow)
                  {
                  ui->setupUi(this);
                  Dialog *d= new Dialog();
                  d->show();
                  setCentralWidget(d);

                  }
                  @

                  alfah

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kalster
                    wrote on last edited by
                    #9

                    o yes. it worked.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      alfah
                      wrote on last edited by
                      #10

                      :) ok, [Solved] i guess

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        kalster
                        wrote on last edited by
                        #11

                        not yet. the setCentralWidget(tt); hides the widgets on my mainwindow

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          alfah
                          wrote on last edited by
                          #12

                          ofcourse it will!! because what you have done is callin a form from the MainWindow, so it will be shown over the MainWindow. You din tell me you had widgets on the MainWindow!

                          1 Reply Last reply
                          0
                          • K Offline
                            K Offline
                            kalster
                            wrote on last edited by
                            #13

                            is there another way around this?

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              alfah
                              wrote on last edited by
                              #14

                              would you explain a bit on what is there on the mainWindow and what exactly you want to do ?How do you want to display??

                              alfah

                              1 Reply Last reply
                              0
                              • K Offline
                                K Offline
                                kalster
                                wrote on last edited by
                                #15

                                I have a lot of widgets on the mainwindow. when the program loads, it loads the mainwindow and then the dialog. the dialog loaded is not in focus so i need to load the dialog from the mainwindow and then check if the dialog is loaded. if the dialog is not loaded then i need to write some code in the mainwindow.

                                i need to call the dialog checkbox from the mainwindow to determine if the dialog is displayed. if the dialog is not displayed then i can write my code in the dialog.cpp file.

                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  alfah
                                  wrote on last edited by
                                  #16

                                  loaded as in displayed?

                                  1 Reply Last reply
                                  0
                                  • K Offline
                                    K Offline
                                    kalster
                                    wrote on last edited by
                                    #17

                                    yes that's correct

                                    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