Results 1 to 10 of 10

Thread: Menubar actions

  1. #1
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Menubar actions

    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.

    Qt Code:
    1. connect(ui->actionSettings, SIGNAL(triggered()), &dlg, SLOT(newdevice()));
    To copy to clipboard, switch view to plain text mode 

    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??

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Menubar actions

    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?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Menubar actions

    Quote Originally Posted by srohit24 View Post
    Qt Code:
    1. connect(ui->actionSettings, SIGNAL(triggered()), &dlg, SLOT(newdevice()));
    To copy to clipboard, switch view to plain text mode 
    .. and it seems further that you have created it locally on the stack, which is also a "bad" idea.

  4. #4
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Menubar actions

    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.

    Qt Code:
    1. {
    2. QDialog dlg;
    3. Ui::newdevice newui;
    4. newui.setupUi(&dlg);
    5.  
    6. connect(newui.updateButton, SIGNAL(clicked()), &dlg, SLOT(close()));
    7. newui.linklabel->setOpenExternalLinks(1);
    8.  
    9. identityreaddata();
    10. dlg.setWindowTitle("Desktop Uploader");
    11. newui.statuslabel->setText("Please enter the details. All fields are mandatory.");
    12.  
    13. if(conditon satisfied)
    14. {
    15. //get all data.
    16. }
    17. else
    18. {
    19. qDebug() << "Please enter all the details.";
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Menubar actions

    Isnt dlg being created on stack ? Try creating on heap

  6. #6
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Menubar actions

    and where is you newdevice() method defined? can you show the class and method declaration and implementation?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Menubar actions

    May that
    Qt Code:
    1. connect(ui->actionSettings, SIGNAL(triggered()), &dlg, SLOT(newdevice()));
    To copy to clipboard, switch view to plain text mode 
    be
    Qt Code:
    1. connect(ui->actionSettings, SIGNAL(triggered()), this, SLOT(newdevice()));
    To copy to clipboard, switch view to plain text mode 
    since newdevice is not a member function of dlg.

  8. #8
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: Menubar actions

    Qt Code:
    1. #ifndef CORE_H
    2. #define CORE_H
    3.  
    4. #include <QtGui/QMainWindow>
    5. #include <QSystemTrayIcon>
    6. #include <QAction>
    7.  
    8. typedef unsigned char bytearray;
    9.  
    10. namespace Ui
    11. {
    12. class desktop;
    13. class newdevice;
    14. }
    15.  
    16. class desktop : public QMainWindow
    17. {
    18. Q_OBJECT
    19. Q_ENUMS(size)
    20. Q_ENUMS(address)
    21.  
    22. public:
    23. desktop(QWidget *parent = 0);
    24. void devicestatus();
    25. void newdevice();
    26. void converttochar(bytearray a[], int n,char names[][9]);
    27. ~desktop();
    28.  
    29. private slots:
    30. void readdata();
    31. void getLineEditText();
    32. void identityreaddata();
    33. void senddata();
    34. void writedata(QString byte,int size);
    35. void time();
    36. void intialsetup();
    37.  
    38. void iconActivated( QSystemTrayIcon::ActivationReason reason );
    39.  
    40. private:
    41. Ui::desktop *ui;
    42. };
    43.  
    44. #endif // CORE_H
    To copy to clipboard, switch view to plain text mode 

    this is my core.h file.

    Qt Code:
    1. void desktop::intialsetup()
    2. {
    3. createActions();
    4. devicestatus();
    5. writedata(byte,9);
    6. newdevice();
    7. }
    To copy to clipboard, switch view to plain text mode 

    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?

    Qt Code:
    1. connect(ui->actionSettings, SIGNAL(triggered()), &dlg, SLOT(newdevice()));
    2.  
    3. connect(ui->actionSettings, SIGNAL(triggered()), this, SLOT(newdevice()));
    To copy to clipboard, switch view to plain text mode 

    this doesnt work

  9. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Menubar actions

    Maybe you should define newdevice() as a slot...

  10. #10
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Menubar actions

    Maybe you should read this first: http://doc.qtsoftware.com/4.5/signalsandslots.html
    because your connect() doesn't make any sense.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. Logging Qt User Actions
    By Frank J. Lhota in forum Qt Programming
    Replies: 14
    Last Post: 30th May 2014, 22:36
  2. Finding menuBar actions
    By maverick_pol in forum Qt Programming
    Replies: 2
    Last Post: 10th April 2008, 01:14
  3. Showing and hiding menubar
    By borges in forum Newbie
    Replies: 1
    Last Post: 23rd September 2007, 11:56
  4. QActions don't work with menubar hidden
    By Pepe in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2007, 02:04
  5. Replies: 2
    Last Post: 12th November 2006, 09:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.