aatwo
18th March 2011, 11:08
Hey guys :)
I am writing a QT application and I have hit a bit of a wall.
I have a file containing an undetermined number of data entries (blocks of 512 bytes). Each data entry contains a collection of variables as well as a data entry name, and a data entry category.
I have created the code to look at this file and generate a QMenu. Basically the code creates sub-menus for each unique category found in the file, and then obtains the name of each data entry and places it in the correct category.
This works fine and the menu appears as expected however the next step is where I am struggling. I have a function that requires arguments extracted from the data entry.
So my question is this :) How can I add the required function calls to the QActions?
Here is an extract of the relevant part of my code! :)
// Create the menu structure
// *********************
// ** CREATE BASE MENU
QMenu *menu = new QMenu((QWidget*)ui->button);
// *********************
for(int i = 0; i < numberOfCategories; i++){
// *******************
// ** CREATE SUB MENU
QMenu *submenu = new QMenu(dataEntryCategoryNameList[i], (QWidget*)menu);
// *******************
// ** FIND ALL DATA ENTRIES THAT ARE PART OF THE CURRENT CATEGORY
for(int j = 0; j < dataEntryCount; j++){
if(memcmp(dataEntryCategoryNameList[i], &dataEntryRawDataList[j][220], 30)==0){
// **********************
// ** ADD ACTION TO MENU
char temp[30];
memset(temp, 0x00, 30);
memcpy(temp, &dataEntryRawDataList[j][0], 30);
// OBTAIN RELEVANT COMMAND OPTIONS FOR THE CURRENT DATA ENTRY
int var1 = /*value obtained from file*/
int var2 = /*value obtained from file*/
int var3 = /*value obtained from file*/
int var4 = /*value obtained from file*/
int var5 = /*value obtained from file*/
//Function I want to call for the current data entry:
// myFunction(var1, var2, var3, var4, var5)
QAction *action = new QAction(temp, (QObject*)submenu);
submenu->addAction(action);
// **********************
}
}
menu->addMenu(submenu);
}
menu->exec(QCursor::pos());
Thanks for reading and I appreciate any help! :D
I am writing a QT application and I have hit a bit of a wall.
I have a file containing an undetermined number of data entries (blocks of 512 bytes). Each data entry contains a collection of variables as well as a data entry name, and a data entry category.
I have created the code to look at this file and generate a QMenu. Basically the code creates sub-menus for each unique category found in the file, and then obtains the name of each data entry and places it in the correct category.
This works fine and the menu appears as expected however the next step is where I am struggling. I have a function that requires arguments extracted from the data entry.
So my question is this :) How can I add the required function calls to the QActions?
Here is an extract of the relevant part of my code! :)
// Create the menu structure
// *********************
// ** CREATE BASE MENU
QMenu *menu = new QMenu((QWidget*)ui->button);
// *********************
for(int i = 0; i < numberOfCategories; i++){
// *******************
// ** CREATE SUB MENU
QMenu *submenu = new QMenu(dataEntryCategoryNameList[i], (QWidget*)menu);
// *******************
// ** FIND ALL DATA ENTRIES THAT ARE PART OF THE CURRENT CATEGORY
for(int j = 0; j < dataEntryCount; j++){
if(memcmp(dataEntryCategoryNameList[i], &dataEntryRawDataList[j][220], 30)==0){
// **********************
// ** ADD ACTION TO MENU
char temp[30];
memset(temp, 0x00, 30);
memcpy(temp, &dataEntryRawDataList[j][0], 30);
// OBTAIN RELEVANT COMMAND OPTIONS FOR THE CURRENT DATA ENTRY
int var1 = /*value obtained from file*/
int var2 = /*value obtained from file*/
int var3 = /*value obtained from file*/
int var4 = /*value obtained from file*/
int var5 = /*value obtained from file*/
//Function I want to call for the current data entry:
// myFunction(var1, var2, var3, var4, var5)
QAction *action = new QAction(temp, (QObject*)submenu);
submenu->addAction(action);
// **********************
}
}
menu->addMenu(submenu);
}
menu->exec(QCursor::pos());
Thanks for reading and I appreciate any help! :D