Access an object from a promoted class: How can i do that?
Hello!
I have this "TableHist" class where i implement a mousePressEvent. I promoted a QTableWidget to "TableHist". When i click on this table with right, left and middle button, that table should do different things. I say "should do" because i want to access an object created in another class first, but i don't know how to get access. How can i do that?
Code:
#ifndef TABLEHIST_H
#define TABLEHIST_H
#include <iostream>
#include <QMouseEvent>
#include <QTableWidget>
// Object i want to access.
#include "database.h"
using namespace std;
public:
};
#endif // TABLEHIST_H
Code:
#include "tablehist.h"
if(event->button( ) == Qt::RightButton) {
//Do something with that object.
}
else if (event->button( ) == Qt::LeftButton) {
//Do something with that object.
}
else {
//Do something with that object.
}
}
Thanks!
Re: Access an object from a promoted class: How can i do that?
I am not sure I fully understand what you mean.
Simply pass the other object to the TableHist object with a setter method?
Cheers,
_
Re: Access an object from a promoted class: How can i do that?
But since this class is used for mousepressevent i don't know where the object of TableHist is instantiated so i can use some "db.setDataBase(...)" method, like you said. That is the real problem, i don't know where this object is instantiated so i can use it. I believe he is instantiated in somewhere because the QTableWidget uses my mousepressevent.
Re: Access an object from a promoted class: How can i do that?
Problem solved guys. I realized that the instantied object is the table i see when i start my program. So, i created a setter method just like anda_skoa said.
But now i'm having another problem. I have this mousepressevent and i want to test it. I want to see (row, collumn) when i press the left button. But when i do that, nothing happens, "cout" just shows me (x, y) when i press other button after that. It seems he holds the result(x, y) and shows me when i click in another button.
Code:
if(event->button( ) == Qt::RightButton) {
cout << "Right" << endl;
}
else if (event->button( ) == Qt::LeftButton) {
cout << "(" << this->currentRow( ) << ", " << this->currentColumn( ) << "): ";
}
else {
cout << "Middle" << endl;
}
}