Hello!
I started another topic yesterday, but I guess it went far into detail.
My questions comes down to this:
How can I correctly re-assign a pointer?
In my case, I have a QtDesigner-Layout, which creates a QTableView:
public:
...
{
...
}
public:
QTableView *tableView;
...
void setupUi(QDialog *AddressBook)
{
tableView = new QTableView(AddressBook);
...
}
To copy to clipboard, switch view to plain text mode
In the class which uses this layout I want to pass a pointer to a pre-defined QTableView to the one created by the layout.
AddressBook-class:
AddressBook
::AddressBook(DataManager
* dmgr,
QWidget *parent
): QDialog(parent
){
...
tableView = dmgr->customerTableView();
...
}
AddressBook::AddressBook(DataManager* dmgr, QWidget *parent): QDialog(parent)
{
...
tableView = dmgr->customerTableView();
...
}
To copy to clipboard, switch view to plain text mode
DataManager-class
...
...
...
{
return m_customerTableView;
}
...
...
QTableView *m_customerTableView;
QTableView *customerTableView();
...
m_customerTableView = new QTableView;
...
QTableView *DataManager::customerTableView()
{
return m_customerTableView;
}
...
To copy to clipboard, switch view to plain text mode
I guess to avoid memory leaks I have to delete the original tableView created by QtDesigner.
I tried the following but could get it running, since I am not so familiar with pointers yet. (coming from Java) So there could be a misunderstanding on how pointers work.
In AddressBook-class:
delete tableView;
QTableView *tableView
= dmgr
->customerTableView
();
delete tableView;
QTableView *tableView = dmgr->customerTableView();
To copy to clipboard, switch view to plain text mode
I hope you can help me.
Kind regards,
HomeR
Bookmarks