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.
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
Code:
int i = 0;
q.exec("SELECT typ_name FROM typ");
while (q.next()){
sTypName = q.value(0).toString();
acList[i]->setText(sTypName);
acList[i]->setCheckable(true);
agFilter->addAction(acList[i]);
meListe->addAction(acList[i]);
connect(acList[i], SIGNAL (triggered(bool)), this, SLOT (typFilter()));
i++; }
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
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.
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)".
Code:
connect(sender, SIGNAL(triggered()), receiver, "2execute(int)");