Ctd when accessing Ui::MainWindow from another class
-
Here is the class right here. I'm trying to get the buttongroup to hide but when it fires I get a ctd.
uninstall.h
@
#ifndef UNINSTALL_H
#define UNINSTALL_H#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "uninstall.h"class Uninstall
{
public:
Uninstall();
void hide();private:
Ui::MainWindow *ui;};
#endif // UNINSTALL_H
@uninstall.cpp
@Uninstall::Uninstall()
{
MainWindow *mw = new MainWindow();}
void Uninstall::hide() {
ui->buttonWidget->hide();
}@
MainWindow.cpp
@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "uninstall.h"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_pushButton_Next_clicked()
{
Uninstall *uninstallObj;if (ui->radioButton_Uninstall->isChecked()) { uninstallObj->hide(); }
}
Ui::MainWindow* MainWindow::getUi()
{
return ui;
}@
-
@Uninstall *uninstallObj;
if (ui->radioButton_Uninstall->isChecked()) {uninstallObj->hide();@
Your uninstallObj is not initialised. So it will crash. Also what is ctd ?
-
I think, Here uninstallObj->show(); is missing. then uninstallObj->hide(); should not work.
-
[quote author="Dheerendra" date="1403675821"]
@Uninstall *uninstallObj;
if (ui->radioButton_Uninstall->isChecked()) {uninstallObj->hide();@
Your uninstallObj is not initialised. So it will crash. Also what is ctd ? [/quote]
ctd stand for crash to desktop.
That didn't fix issue. -
[quote author="ankursaxena" date="1403681027"]I think, Here uninstallObj->show(); is missing. then uninstallObj->hide(); should not work.
[/quote]That can't be right because hide() is a method I created in class Uninstall, its not a property.
-
Oh. I haven't noticed that
-
but you should avoid such kind of nomination . It creates confusion and can be error-prone.
-
the best way to identify the ctd is to use qDebug() statemnts ,
Try it. then you can find the place where is crash starting. -
[quote author="IamSumit" date="1403686743"]the best way to identify the ctd is to use qDebug() statemnts ,
Try it. then you can find the place where is crash starting.[/quote]I'm able to get information from Ui::MainWindow, like text from labels, but I am not able to adjust properties of Ui::MainWindow in class Uninstall.
What's the deal?
-
Hi,
You should create a new Uninstall object.
*uninstallObj is a pointer and it points to nothing in your case and hence the seg fault.
Do this,
@
Uninstall *uninstallObj = new Uninstall;
@ -
[quote author="p3c0" date="1403690252"]Hi,
You should create a new Uninstall object.
*uninstallObj is a pointer and it points to nothing in your case and hence the seg fault.
Do this,
@
Uninstall *uninstallObj = new Uninstall;
@[/quote]That's not it. I can get to the Uninstall class successfully. I test uing qDebug.
I just can't change properties of Ui::MainWindow from within Uninstall. weird. However I can print
qDebug << Ui::MainWindow->QLabel->text();
From within Uninstall class -
So is the crashing issue solved ?
For changing properties from one class to other i would suggest you to use "Signals and Slots mechanism":http://qt-project.org/doc/qt-4.8/signalsandslots.html. -
[quote author="p3c0" date="1403692659"]So is the crashing issue solved ?
For changing properties from one class to other i would suggest you to use "Signals and Slots mechanism":http://qt-project.org/doc/qt-4.8/signalsandslots.html.[/quote]No its not solved.
-
I'm still having trouble with this. Could someone show me a simple example of transfering *ui to another class using signals and slots?
-
Hi
If your problem is still there
take a look on the following link
http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
hope it helps :)