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. how to call Mainwindow method from a childwindow.cpp
Forum Updated to NodeBB v4.3 + New Features

how to call Mainwindow method from a childwindow.cpp

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 2 Posters 2.2k 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.
  • M moyin

    @moyin said in how to call Mainwindow method from a childwindow.cpp:

    @jsulm thnks for rply,
    this is my mainwindow.cpp (constructor)

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

    ui->setupUi(this);
    QFont font("Plastique",10);
    

    // font.setStyleHint(QFont::Monospace);
    QApplication::setFont(font);
    ui->tabWidget_Main->setHidden(true);

    ui->tabWidget_CELL_CONFIG->setHidden(true);
    ui->tableWidget_cell_config_2->setColumnWidth(4,250);
    Disable_Root_Tabs();
    Disable_LS_Buttons();
    

    // Import *temp = new Import() ;
    // connect(temp, SIGNAL(after_import()),this, SLOT(slot_load_cell_dropdownlist()));
    imp = new Import() ;
    connect(imp, SIGNAL(after_import()),this, SLOT(slot_load_cell_dropdownlist()));

    }

    this is my import.cpp where i'm emitting signal.

    #include "import.h"
    #include "ui_import.h"
    #include <QFileDialog>
    #include <QMessageBox>
    #include "JailHouseCellList.h"
    #include "readfromdump/ReadDmp.h"
    #include "mainwindow.h"
    #include <iostream>

    Import::Import(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Import)
    {
    ui->setupUi(this);
    QFont font("Plastique",10);
    // font.setStyleHint(QFont::Monospace);
    QApplication::setFont(font);

    }

    Import::~Import()
    {
    delete ui;
    }

    void Import::on_pushButton_import_config_clicked()
    {
    QString filepath = QFileDialog::getOpenFileName(this, tr("Import file"), "/home","Config_Files(*.info)") ;
    ui->lineEdit_config_File->setText(filepath);
    }

    void Import::on_pushButton_import_dump_clicked()
    {
    QString filepath = QFileDialog::getOpenFileName(this, tr("Import file"), "/home","Dump_Files(*.dmp)") ;
    ui->lineEdit_Dump_File->setText(filepath);
    }

    void Import::on_pushButton_create_imported_config_clicked()
    {
    try{
    std::string info_file = ui->lineEdit_config_File->text().toStdString() ;
    std::string dump_file = ui->lineEdit_Dump_File->text().toStdString() ;
    JailHouseCellList & JL = JailHouseCellList::getJailHouseCellList();
    ReadDmp jt(info_file,dump_file);
    JailHouseCell * jc = jt.get_cell();
    if( RootCell * j = dynamic_cast<RootCell * >(jc) )
    JL.add_rootcell_no_validation(*j);
    else
    JL.add_cell_no_validation(*jc);
    }
    catch(JailHouseCell_error & e)
    {
    std::string s = e.what();
    QMessageBox::warning(this,"Wrong input",e.what()) ;
    }
    catch(std::exception & e)
    {
    std::string s = e.what();
    QMessageBox::warning(this,"Wrong input",e.what()) ;
    }
    catch(...)
    {
    QMessageBox::warning(this,"unknownerror","unknownerror");
    }
    emit after_import();

    }

    //void Import::after_import() {
    // std::cout << "calling load_dropdownList() function" << std::endl ;
    //}

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #7

    @moyin Are you sure signal is emitted?

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    M 1 Reply Last reply
    0
    • jsulmJ jsulm

      @moyin Are you sure signal is emitted?

      M Offline
      M Offline
      moyin
      wrote on last edited by
      #8

      @jsulm thanks for rply,
      i dont how to confirm the signal is emitted or not but when i run the application in debug mode and step into emit after_import(); it takes me into this code snippet. that i already shared you.

      / SIGNAL 0
      void Import::after_import()
      {
      QMetaObject::activate(this, &staticMetaObject, 0, 0);
      }
      QT_END_MOC_NAMESPACE

      jsulmJ 1 Reply Last reply
      0
      • M moyin

        @jsulm thanks for rply,
        i dont how to confirm the signal is emitted or not but when i run the application in debug mode and step into emit after_import(); it takes me into this code snippet. that i already shared you.

        / SIGNAL 0
        void Import::after_import()
        {
        QMetaObject::activate(this, &staticMetaObject, 0, 0);
        }
        QT_END_MOC_NAMESPACE

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #9

        @moyin You can just put a breakpoint in your slot. Or when you're in that code block then just go further (step) to see what is happening.
        Also do

        qDebug() << connect(imp, SIGNAL(after_import()),this, SLOT(slot_load_cell_dropdownlist()));
        

        to see whether the connection was actually successful.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • M Offline
          M Offline
          moyin
          wrote on last edited by
          #10

          @jsulm , yes! that is
          qDebug() << connect(imp, SIGNAL(after_import()),this, SLOT(slot_load_cell_dropdownlist()));
          returning true.

          And if i put BreakPoint in slot_load_cell_dropdownlist(). debugger not reaching to that BreakPoint.

          jsulmJ 1 Reply Last reply
          0
          • M moyin

            @jsulm , yes! that is
            qDebug() << connect(imp, SIGNAL(after_import()),this, SLOT(slot_load_cell_dropdownlist()));
            returning true.

            And if i put BreakPoint in slot_load_cell_dropdownlist(). debugger not reaching to that BreakPoint.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #11

            @moyin Do you by any chance have more than one Import instance?
            And what are you doing in slot_load_cell_dropdownlist()?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            M 1 Reply Last reply
            0
            • jsulmJ jsulm

              @moyin Do you by any chance have more than one Import instance?
              And what are you doing in slot_load_cell_dropdownlist()?

              M Offline
              M Offline
              moyin
              wrote on last edited by
              #12

              @jsulm
              @ Do you by any chance have more than one Import instance?
              YES!
              Actually i have 2 import instance to the same pointer (imp) .

              @what are you doing in slot_load_cell_dropdownlist()?
              i am just reinitialising a Qcombobox.

              jsulmJ 1 Reply Last reply
              0
              • M moyin

                @jsulm
                @ Do you by any chance have more than one Import instance?
                YES!
                Actually i have 2 import instance to the same pointer (imp) .

                @what are you doing in slot_load_cell_dropdownlist()?
                i am just reinitialising a Qcombobox.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #13

                @moyin said in how to call Mainwindow method from a childwindow.cpp:

                Actually i have 2 import instance to the same pointer (imp) .

                What?! Why? Then the first one is lost as you overwrite the pointer when you create the second instance. And which of them did you actually connected?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                M 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @moyin said in how to call Mainwindow method from a childwindow.cpp:

                  Actually i have 2 import instance to the same pointer (imp) .

                  What?! Why? Then the first one is lost as you overwrite the pointer when you create the second instance. And which of them did you actually connected?

                  M Offline
                  M Offline
                  moyin
                  wrote on last edited by
                  #14

                  @jsulm Now i changed my code like,

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

                  ui->setupUi(this);
                  QFont font("Plastique",10);
                  

                  // font.setStyleHint(QFont::Monospace);
                  QApplication::setFont(font);
                  ui->tabWidget_Main->setHidden(true);

                  ui->tabWidget_CELL_CONFIG->setHidden(true);
                  ui->tableWidget_cell_config_2->setColumnWidth(4,250);
                  Disable_Root_Tabs();
                  Disable_LS_Buttons();
                  

                  // Import *temp = new Import() ;
                  // connect(temp, SIGNAL(after_import()),this, SLOT(slot_load_cell_dropdownlist()));
                  imp2 = new Import(this) ;
                  std::cout << "just before connect" << std::endl;
                  qDebug() << connect(imp2, SIGNAL(after_import()),this, SLOT(slot_load_cell_dropdownlist()));
                  std::cout << "just after connect" << std::endl;
                  }

                  M 1 Reply Last reply
                  0
                  • M moyin

                    @jsulm Now i changed my code like,

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

                    ui->setupUi(this);
                    QFont font("Plastique",10);
                    

                    // font.setStyleHint(QFont::Monospace);
                    QApplication::setFont(font);
                    ui->tabWidget_Main->setHidden(true);

                    ui->tabWidget_CELL_CONFIG->setHidden(true);
                    ui->tableWidget_cell_config_2->setColumnWidth(4,250);
                    Disable_Root_Tabs();
                    Disable_LS_Buttons();
                    

                    // Import *temp = new Import() ;
                    // connect(temp, SIGNAL(after_import()),this, SLOT(slot_load_cell_dropdownlist()));
                    imp2 = new Import(this) ;
                    std::cout << "just before connect" << std::endl;
                    qDebug() << connect(imp2, SIGNAL(after_import()),this, SLOT(slot_load_cell_dropdownlist()));
                    std::cout << "just after connect" << std::endl;
                    }

                    M Offline
                    M Offline
                    moyin
                    wrote on last edited by
                    #15

                    @jsulm
                    Same result it is not calling slot_load_cell_dropdownlist() at all.

                    M 1 Reply Last reply
                    0
                    • M moyin

                      @jsulm
                      Same result it is not calling slot_load_cell_dropdownlist() at all.

                      M Offline
                      M Offline
                      moyin
                      wrote on last edited by
                      #16

                      yeah! man its working thanks alot.

                      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