Results 1 to 10 of 10

Thread: How to change the menubar after log in as super user.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default How to change the menubar after log in as super user.

    Hello, I am writing an app which after the main window shows it has a menubar with the option to connect, with a "super" user which has some adittional menus/actions.
    The thing is that I have different classes for different menubars and another class for creating the dialog.
    The issue is that I cannot figure it out how to actually change the menubar.
    Here is the main window header file:
    Qt Code:
    1. #ifndef CAMER_H
    2. #define CAMER_H
    3.  
    4. #include <QMainWindow>
    5. #include <QSettings>
    6. #include <QDialog>
    7. #include <QDialogButtonBox>
    8. #include <QLabel>
    9. #include <QLineEdit>
    10. #include <QGridLayout>
    11. #include <QPushButton>
    12. namespace Ui {
    13. class camer;
    14. }
    15.  
    16. class camer : public QMainWindow
    17. {
    18. Q_OBJECT
    19.  
    20. public:
    21. explicit camer(QWidget *parent = 0);
    22. ~camer();
    23. void setMeniuAdmin();
    24. void setMeniuNeaut();
    25. private:
    26. Ui::camer *ui;
    27. private slots:
    28. void creareDialogConect();
    29. public slots:
    30. };
    31.  
    32. #endif // CAMER_H
    To copy to clipboard, switch view to plain text mode 

    here is the main window cpp file:
    Qt Code:
    1. #include "camer.h"
    2. #include "conn.h"
    3. #include "FerDialConect.h"
    4. #include "meniuNeautentificat.h"
    5. #include "meniuAdmin.h"
    6. camer::camer(QWidget *parent):QMainWindow(parent){
    7. setMinimumSize(800,600);
    8. setMeniuNeaut();
    9. }
    10.  
    11. camer::~camer()
    12. {
    13. //settings saving function goes here
    14. }
    15.  
    16.  
    17. void camer::creareDialogConect(){
    18. FerDialConect *fdc=new FerDialConect(this);
    19. fdc->afisDial();
    20. }
    21.  
    22. void camer::setMeniuNeaut(){
    23. menNeaut *mn=new menNeaut(this);
    24. setMenuBar(mn);
    25. }
    26.  
    27. void camer::setMeniuAdmin(){
    28. MeniuAdmin *mad=new MeniuAdmin(this);
    29. setMenuBar(mad);
    30. }
    To copy to clipboard, switch view to plain text mode 

    here are the dialog header and cpp files:
    Qt Code:
    1. #ifndef FERDIALCONECT_H
    2. #define FERDIALCONECT_H
    3. #include <QDialog>
    4. #include <QGridLayout>
    5. #include <QLabel>
    6. #include <QLineEdit>
    7. #include <QDialogButtonBox>
    8. #include <QMessageBox>
    9. #include <QPushButton>
    10. #include "camer.h"
    11. class FerDialConect:public camer{
    12. Q_OBJECT
    13. public:
    14. explicit FerDialConect(camer *parent = 0);
    15. void afisDial();
    16. QString util,parola;
    17. private:
    18. QGridLayout *amplasareDialCon,*amplasareDialCon1,*amplasareDialCon2;
    19. QLabel *etUtil,*etPar;
    20. QLineEdit *txtUtil,*txtPar;
    21. QPushButton *bCon,*bAnul;
    22. QDialogButtonBox *cutieButCon;
    23. QDialog *dialogConect;
    24. private slots:
    25. void con();
    26. };
    27.  
    28. #endif // FERDIALCONECT_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "FerDialConect.h"
    2. #include "meniuAdmin.h"
    3.  
    4. FerDialConect::FerDialConect(camer *parent):camer(parent){
    5. dialogConect=new QDialog(this);
    6. amplasareDialCon=new QGridLayout;
    7. amplasareDialCon1=new QGridLayout;
    8. amplasareDialCon2=new QGridLayout;
    9. etUtil=new QLabel(tr("Utilizator"));
    10. etPar=new QLabel(tr("Parola"));
    11. txtUtil=new QLineEdit(util);
    12. txtPar=new QLineEdit(parola);
    13. txtPar->setEchoMode(QLineEdit::Password);
    14. cutieButCon=new QDialogButtonBox;
    15. cutieButCon->setOrientation(Qt::Horizontal);
    16. bCon=new QPushButton(tr("Conectare"));
    17. bAnul=new QPushButton(tr("Anulare"));
    18. cutieButCon->addButton(bCon,QDialogButtonBox::AcceptRole);
    19. cutieButCon->addButton(bAnul,QDialogButtonBox::RejectRole);
    20. connect(cutieButCon,SIGNAL(rejected()),dialogConect,SLOT(reject()));
    21. connect(cutieButCon,SIGNAL(accepted()),this,SLOT(con()));
    22. amplasareDialCon->addLayout(amplasareDialCon1,0,0);
    23. amplasareDialCon->addLayout(amplasareDialCon2,1,0);
    24. amplasareDialCon1->addWidget(etUtil,0,0);
    25. amplasareDialCon1->addWidget(txtUtil,0,1);
    26. amplasareDialCon1->addWidget(etPar,1,0);
    27. amplasareDialCon1->addWidget(txtPar,1,1);
    28. amplasareDialCon2->addWidget(cutieButCon,0,0);
    29. }
    30.  
    31. void FerDialConect::afisDial(){
    32. dialogConect->setLayout(amplasareDialCon);
    33. dialogConect->setFixedSize(300,200);
    34. dialogConect->exec();
    35. }
    36.  
    37. void FerDialConect::con(){
    38. util=txtUtil->text();
    39. int marimeUtil=util.size();
    40. parola=txtPar->text();
    41. int marimePar=parola.size();
    42. if(marimeUtil==0 && marimePar!=0){
    43. QMessageBox::critical(this, tr("Eroare"), tr("Campul de utilizator este necompletat."));
    44. return;
    45. }
    46. else if(marimeUtil!=0 && marimePar==0){
    47. QMessageBox::critical(this, tr("Eroare"), tr("Campul de parola este necompletat."));
    48. return;
    49. }
    50. else if(marimeUtil==0 && marimePar==0){
    51. QMessageBox::critical(this, tr("Eroare"), tr("Campurile sunt necompletate."));
    52. return;
    53. }
    54. else {
    55. if(util=="admin" && parola=="camer"){
    56. dialogConect->accept();
    57. camer::setMeniuAdmin();
    58. }
    59.  
    60. }
    61. }
    To copy to clipboard, switch view to plain text mode 

    here is the default menubar files:
    Qt Code:
    1. #ifndef MENIUNEAUTENTIFICAT_H
    2. #define MENIUNEAUTENTIFICAT_H
    3. #include <QMenuBar>
    4. #include <QMenu>
    5. #include <QAction>
    6. #include "camer.h"
    7.  
    8. class menNeaut:public QMenuBar{
    9. Q_OBJECT
    10. public:
    11. explicit menNeaut(camer *parent=0);
    12. private:
    13. QMenu *meniuStandard;
    14. QAction *conectare,*inchideApp;
    15. private slots:
    16. };
    17.  
    18. #endif // MENIUNEAUTENTIFICAT_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "meniuNeautentificat.h"
    2. menNeaut::menNeaut(camer *parent):QMenuBar(parent){
    3. meniuStandard=new QMenu("Meniu");
    4. conectare=new QAction(tr("Conectare"),this);
    5. connect(conectare,SIGNAL(triggered()),parent,SLOT(creareDialogConect()));
    6. inchideApp=new QAction(tr("Inchide"),this);
    7. connect(inchideApp,SIGNAL(triggered()),parent,SLOT(inchideApplicatie()));
    8. meniuStandard->addAction(conectare);
    9. meniuStandard->addAction(inchideApp);
    10. addMenu(meniuStandard);
    11. }
    To copy to clipboard, switch view to plain text mode 

    here are the files for the second menu(its just a basic setup):
    Qt Code:
    1. #ifndef MENIUADMIN_H
    2. #define MENIUADMIN_H
    3. #include <QMenuBar>
    4. #include "camer.h"
    5. #include <QMenu>
    6. #include <QAction>
    7.  
    8. class MeniuAdmin:public QMenuBar{
    9. Q_OBJECT
    10. public:
    11. explicit MeniuAdmin(camer *parent=0);
    12. private:
    13. QMenu *meniu;
    14. QAction *dateP;
    15. private slots:
    16. };
    17.  
    18. #endif // MENIUADMIN_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "meniuAdmin.h"
    2. MeniuAdmin::MeniuAdmin(camer *parent):QMenuBar(parent){
    3. meniu=new QMenu(tr("Meniu"),this);
    4. dateP=new QAction(tr("Date Personale"),this);
    5. meniu->addAction(dateP);
    6. addMenu(meniu);
    7. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by adutzu89; 20th January 2014 at 14:13.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to change the menubar after log in as super user.

    I have no idea what your actual problem is, but you have same very strange code in FerDialConect::con()

    Qt Code:
    1. if(util=="admin" && parola=="camer"){
    2. dialogConect->accept();
    3. camer c;
    4. c.setMeniuAdmin();
    5. }
    To copy to clipboard, switch view to plain text mode 
    This creates a new "camer" main window, tells it to show the admin menu and then destroys it (camer goes out of scope).
    It also calls accept() on another dialog.

    Cheers,
    _

  3. #3
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to change the menubar after log in as super user.

    I am trying to use
    Qt Code:
    1. camer::setMeniuAdmin()
    To copy to clipboard, switch view to plain text mode 
    ,
    Qt Code:
    1. dialogConect->accept()
    To copy to clipboard, switch view to plain text mode 
    is called because I created it inside FerDialConect class(because I made it a child of camer class).

    I've changed my code from
    Qt Code:
    1. camer c;
    2. c.setMeniuAdmin();
    To copy to clipboard, switch view to plain text mode 
    to
    Qt Code:
    1. camer::setMeniuAdmin()
    To copy to clipboard, switch view to plain text mode 

    but still no response as I get cannot call void camer::setMeniuAdmin without object.
    Last edited by adutzu89; 20th January 2014 at 14:58.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to change the menubar after log in as super user.

    Quote Originally Posted by adutzu89 View Post
    Qt Code:
    1. dialogConect->accept()
    To copy to clipboard, switch view to plain text mode 
    is called because I created it inside FerDialConect class(because I made it a child of camer class).
    I see. Usually a dialog is implemented inside its own class and simply use from elsewhere.

    Quote Originally Posted by adutzu89 View Post
    I've changed my code from
    Qt Code:
    1. camer c;
    2. c.setMeniuAdmin();
    To copy to clipboard, switch view to plain text mode 
    to
    Qt Code:
    1. camer::setMeniuAdmin()
    To copy to clipboard, switch view to plain text mode 

    but still no response as I get cannot call void camer::setMeniuAdmin without object.
    This is strange, the class FerDialConect is derived from camer so that should work. Try just the method
    Qt Code:
    1. setMeniuAdmin();
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  5. #5
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to change the menubar after log in as super user.

    Thank you for taking the time to help, it does not work with no error whatsoever, not even at runtime.
    I've tried even connecting signals of
    Qt Code:
    1. accept()
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. reject()
    To copy to clipboard, switch view to plain text mode 
    buttons from dialog to
    Qt Code:
    1. setMeniuAdmin()
    To copy to clipboard, switch view to plain text mode 
    (after moving the function to public slots).
    The function works as I made a central widget,added 2 butons to switch between the menubars but that was only in camer class.
    It must be my parent-child relationship, but I cannot figure it out.
    Last edited by adutzu89; 20th January 2014 at 21:16.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to change the menubar after log in as super user.

    You could make a ZIP file of your project and attach it.

    Cheers,
    _

  7. #7
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: How to change the menubar after log in as super user.

    Ok I will uploaded it. Thank you.
    PS: There are some elements that I added to test functionality in camer.cpp. And didn't had time to clean the project before uploading it, have a exam that I need to go, also the I am using Qt 5.2.
    Attached Files Attached Files
    Last edited by adutzu89; 21st January 2014 at 09:30.

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to change the menubar after log in as super user.

    First check if you really want FerDialConect to be of type "camer", i.e. a main window.
    The slot that creates it is called creareDialogConect which would indicate that FerDialConect is a dialog.

    If you want to change the menu of the camer instance that is created in main(), then you have to call its setMeniuAdmin().

    For example after fdc->afisDial() returns or, after making setMeniuAdmin() a slot, have FerDialConect emit a signal and connect it to the setMeniuAdmin().

    Cheers,
    _

  9. The following user says thank you to anda_skoa for this useful post:

    adutzu89 (22nd January 2014)

Similar Threads

  1. Replies: 2
    Last Post: 9th September 2013, 22:12
  2. change image by user
    By smemamian in forum Newbie
    Replies: 1
    Last Post: 10th July 2013, 22:18
  3. Change background color of one menubar item eg Help in blue
    By maulik_887 in forum Qt Programming
    Replies: 5
    Last Post: 9th April 2012, 13:41
  4. change the text colour in Menubar
    By chinmayapadhi in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2010, 01:31
  5. Running shell script with as super user in N900
    By spylvas in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 30th April 2010, 01:05

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
  •  
Qt is a trademark of The Qt Company.