Solved how to call Mainwindow method from a childwindow.cpp
-
@moyin Your problem is for sure not in this code. Either the signal is not emitted, or not connected to slot, or (like I suggested before) you actually use the wrong Import instance (as you create a new temporary instance which you connect then)...
Can you show your code after applying my suggestion? -
@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()));}
-
@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 ;
//} -
@moyin Are you sure signal is emitted?
-
@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 -
@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 doqDebug() << connect(imp, SIGNAL(after_import()),this, SLOT(slot_load_cell_dropdownlist()));
to see whether the connection was actually successful.
-
@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.
-
@moyin Do you by any chance have more than one Import instance?
And what are you doing in slot_load_cell_dropdownlist()? -
@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. -
@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?
-
@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;
} -
@jsulm
Same result it is not calling slot_load_cell_dropdownlist() at all. -
yeah! man its working thanks alot.