PDA

View Full Version : Passing Object to dll



ankurjain
23rd March 2006, 05:51
hi all,
i've to make a dll to provide grid functionality (mostly excel type) like cut, copy,paste, redo,undo,add row, delete row.

These functions are there in context menu as well as can use keyboard shortcuts like Ctrl+X for cut etc...

i've inherited the QTableWidget class.

i've implemented context menu also in a dll function and called the function in the main project.

Now i am implementing the context menu functions.

My problem is how to pass the object of table to the grid function on click of context menu.

My project looks like below.

http://img49.imageshack.us/img49/1125/grid4nf.th.jpg (http://img49.imageshack.us/my.php?image=grid4nf.jpg)

Both upper and lower table are separate pointers (say temp1,temp2) of QGrid type.

I am implementing the delete function.

Following is the code snippet:




// Constructors. creates the grid with x rows, y columns

QGrid::QGrid(int x, int y,QWidget *parent) : QTableWidget(x,y,parent)
{

}

//Creates context menu in main program

void QGrid::setUpContextmenu()
{
addAction(deleterowAct);
setContextMenuPolicy(Qt::ActionsContextMenu);
}

void QGrid::createActions()
{
deleterowAct = new QAction(IDS_DELETEROW, this);
deleterowAct->setStatusTip(tr("Delete a row"));
connect(deleterowAct, SIGNAL(triggered()), this, SLOT(deleteTableRow()));
deleterowAct->setEnabled(true);
}

// delete row function

void QGrid::deleteTableRow()
{
QMessageBox::information(this,"hi","hello");
this->removeRow(this->currentRow());
}






The QMessageBox won't popup on cliking the delete and also the function is not working ... how can i pass the grid object (temp1/temp2). i used this pointer instead ... but it doesn't seem to work.

also my other functions will require the pointers.

what can be done ?

wysota
1st April 2006, 08:41
You have to use signals and slots to connect your grids. You can then use the "sender()" method from within a slot to gain a pointer to the object which sent the signal.

ankurjain
1st April 2006, 09:50
i found the problem,
in my class i hadn't wrote the macro Q_OBJECT, that was the problem.

thanx wysota for ur time ... and sorrry to bug everyone with the post :(