Results 1 to 6 of 6

Thread: Load menu from database

  1. #1
    Join Date
    May 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Load menu from database

    Hi everybody !

    I have a database which contains all Menu Items ,and I set up a connection to load all these items to Menu The code is :

    Qt Code:
    1. .....
    2. for(int x = 0; x < myResults->record().count(); x++)
    3. {
    4. QString fieldName=myResults->value(x).toString();
    5. mAction= new QAction(QIcon(myIconPath+"/mCollectPatrol.png"), tr(fieldName), this);
    6. ...
    7. if(x==3)
    8. [B]connect(mAction, SIGNAL(triggered()), this, SLOT(fieldName));[/B]
    9. ....
    To copy to clipboard, switch view to plain text mode 
    It's successfully loaded item into my menu ,but the Slot doesnot work ! I also looked for QMETAOBJECT but i don't understand it .I'm using QT 4.3.1 .Can anyone help me to find the solution of this problem ?

    Thank for help!

    Le Son
    ------------
    Software Developer -Hanoi University of Science
    Last edited by jpn; 12th May 2008 at 14:49. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Load menu from database

    What does "fieldName" contain? SLOT expects a regular function signature - for example "someName()" and not "somename". Furthermore you have to pass a char * and not a QString - you should use qPrintable() or some other method to get a const char* out of the string.

  3. #3
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: Load menu from database

    I am doing something like this to get a menu from the database. Actually i am a newbie as well .-) so i don't know if it is the best way. But it works.

    agFilter is an actionGroup
    meListe is a menu

    Qt Code:
    1. QString sTypName;
    2. int i = 0;
    3. q.exec("SELECT typ_name FROM typ");
    4. while (q.next()){
    5. sTypName = q.value(0).toString();
    6. acList[i] = new QAction(this);
    7. acList[i]->setText(sTypName);
    8. acList[i]->setCheckable(true);
    9. agFilter->addAction(acList[i]);
    10. meListe->addAction(acList[i]);
    11. connect(acList[i], SIGNAL (triggered(bool)), this, SLOT (typFilter()));
    12. i++; }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    May 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Load menu from database

    Hi Janus,

    I've checked your code ,but what is the slot 'typFilter()' ? Is it the same with all the action in actionGroup .If yes, it's not good because you still write Slot function in your code .My purpose is to design a simple CMS (Content Management System) in QT .You don't need to know coding ,just only work with CMS System. So, I design a Table like this :

    tableMenu (MenuName,ActionName,ActionContent,..)

    with the meaning is: Load 'MenuName' from tableMenu and assign ActionName ,ActionContent to this menuName .

    So when i run program ,if i want to add a new menu Item, i just add new item to database without coding and recompiling project.Do you have any solution for this problem?

    Many Thanks for help.

    Le Son
    ---------------
    Software Developer -Hanoi University of Science

  5. #5
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: Load menu from database

    I did not understand, that you want to load the actions/slots as well from the database. Sry, I have no idea how to do that.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Load menu from database

    To make a slot name connectable, you need to build a string containing a "2", a slot name and slot parameters and pass it instead of the SLOT() macro. So if you want a slot "execute" with a parameter of type "int", you need to create a string "2execute(int)".

    Qt Code:
    1. connect(sender, SIGNAL(triggered()), receiver, "2execute(int)");
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Threads and database connection
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 7th August 2013, 09:30
  2. Docked Widget Menu
    By Chuk in forum Qt Programming
    Replies: 6
    Last Post: 3rd July 2013, 15:12
  3. Multiple database connections
    By cyberboy in forum Qt Programming
    Replies: 3
    Last Post: 30th March 2008, 17:56
  4. Database Master-Detail Entry Form
    By Phan Sin Tian in forum Newbie
    Replies: 4
    Last Post: 3rd February 2008, 15:31
  5. Program not compiling on Fresh install of Leopard
    By dvmorris in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2007, 11:22

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.