PDA

View Full Version : Menubar actions



srohit24
22nd July 2009, 18:24
Hi

I have a menu bar in the mainwindow application.
One of the action in it is to open the settings page.

My settings page is a different UI form, which is of type dialog. I take inputs in this ui.


connect(ui->actionSettings, SIGNAL(triggered()), &dlg, SLOT(newdevice()));

i tried the above code to trigger the settings page, but it doesnt work

it says dlg is undefined. I have declared the dialog dlg in the newdevice function that takes care of all the opearations in settings.

I try to declare QDialog dlg in the main header file, but the app will just crash if i do that.

Any ideas as to how i can fix it??

faldzip
22nd July 2009, 18:59
1. can you show us more code?
2. if I understand you right you have declared dialog dlg in newdevice() method?
So how do you think you can connect some signal to slot that is defined in object that is created in that slot?

Lykurg
22nd July 2009, 19:18
connect(ui->actionSettings, SIGNAL(triggered()), &dlg, SLOT(newdevice()));
.. and it seems further that you have created it locally on the stack, which is also a "bad" idea.

srohit24
23rd July 2009, 05:52
I know that. but when i try to add the QDialog dlg and Ui::newdevice in the main headers, the application just crashes.

I tried all sorts of things for this to work, but with no success.

here is the code snippet for the newdevice function.


{
QDialog dlg;
Ui::newdevice newui;
newui.setupUi(&dlg);

connect(newui.updateButton, SIGNAL(clicked()), &dlg, SLOT(close()));
newui.linklabel->setOpenExternalLinks(1);

identityreaddata();
dlg.setWindowTitle("Desktop Uploader");
newui.statuslabel->setText("Please enter the details. All fields are mandatory.");

if(conditon satisfied)
{
//get all data.
}
else
{
qDebug() << "Please enter all the details.";
}
}

aamer4yu
23rd July 2009, 06:00
Isnt dlg being created on stack ? Try creating on heap

faldzip
23rd July 2009, 06:32
and where is you newdevice() method defined? can you show the class and method declaration and implementation?

Lykurg
23rd July 2009, 07:33
May that
connect(ui->actionSettings, SIGNAL(triggered()), &dlg, SLOT(newdevice()));be
connect(ui->actionSettings, SIGNAL(triggered()), this, SLOT(newdevice()));
since newdevice is not a member function of dlg.

srohit24
23rd July 2009, 08:20
#ifndef CORE_H
#define CORE_H

#include <QtGui/QMainWindow>
#include <QSystemTrayIcon>
#include <QAction>

typedef unsigned char bytearray;

namespace Ui
{
class desktop;
class newdevice;
}

class desktop : public QMainWindow
{
Q_OBJECT
Q_ENUMS(size)
Q_ENUMS(address)

public:
desktop(QWidget *parent = 0);
void devicestatus();
void newdevice();
void converttochar(bytearray a[], int n,char names[][9]);
~desktop();

private slots:
void readdata();
void getLineEditText();
void identityreaddata();
void senddata();
void writedata(QString byte,int size);
void time();
void intialsetup();

void iconActivated( QSystemTrayIcon::ActivationReason reason );

private:
Ui::desktop *ui;
};

#endif // CORE_H

this is my core.h file.


void desktop::intialsetup()
{
createActions();
devicestatus();
writedata(byte,9);
newdevice();
}


this is where i call the newdevice() first.

What i need now is that, when the user click on the menubar->file->settings, this newdevice has to popup again.

How can i create dlg on heap?



connect(ui->actionSettings, SIGNAL(triggered()), &dlg, SLOT(newdevice()));

connect(ui->actionSettings, SIGNAL(triggered()), this, SLOT(newdevice()));

this doesnt work :(

Lykurg
23rd July 2009, 09:08
Maybe you should define newdevice() as a slot...

faldzip
23rd July 2009, 11:35
Maybe you should read this first: http://doc.qtsoftware.com/4.5/signalsandslots.html
because your connect() doesn't make any sense.