Saturday, July 5th 2008, 11:50pm UTC+1

You are not logged in.

  • Login
  • Register

1

Saturday, May 10th 2008, 4:03am

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 :

.....
for(int x = 0; x < myResults->record().count(); x++)
{
QString fieldName=myResults->value(x).toString();
mAction= new QAction(QIcon(myIconPath+"/mCollectPatrol.png"), tr(fieldName), this);
...
if(x==3)
connect(mAction, SIGNAL(triggered()), this, SLOT(fieldName));
....

It's successfully loaded item into my menu ,but the Slot doesnot work ! I also looked for QMETAOBJECT but i don't understand it .Can anyone help me to find the solution of this problem ?

Thank for help!

Le Son
------------
Software Developer -Hanoi University of Science
  • Go to the top of the page

2

Saturday, May 10th 2008, 5:23am

RE: Load menu from database

SLOT is not _the_ function. you need to declare a function, something like

in .h
public slots:
void doSomethingWithFieldName( );


in cpp:

void foo::doSomethingWithFieldName( )
{
//do something ... i presume it involves fieldName :)

}


then you call it in your connect( ....., SLOT(doSomethingWithFieldName( ) );
  • Go to the top of the page

3

Saturday, May 10th 2008, 8:35am

RE: Load menu from database

read Qt Object Model documentation page (file doc/html/object.html)

specially Signals and Slots page (file doc/html/signalsandslots.html)
about use of SIGNAL and SLOT macros
and signal / slot connections
Nicolas
  • Go to the top of the page

4

Sunday, May 11th 2008, 12:05pm

RE: Load menu from database

Hi Nicolas,

I've seen this article ,but i still donnot understand it ?Can you provide a sample for this ? Thank you very much .

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
  • Go to the top of the page

Rate this thread