ItemSell::~ItemSell()
{
delete ui;
}
ItemSell::~ItemSell()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
This is probably corrupting memory and resulting in your sqlQuery constant string getting messed up. The code in your constructor "ui->setup( this )" passes ownership of the ui pointer to the widget, so therefore the ui pointer is getting deleted twice, once by you and once by the widget. Get rid of the delete in your destructor.
void Store::showItem()
{
int id = ui->lstSells->model()->index(m_ind.row(), 0).data().toInt();
ItemSell *item = new ItemSell(this);
item->getSale(id);
item->exec();
}
void Store::showItem()
{
int id = ui->lstSells->model()->index(m_ind.row(), 0).data().toInt();
ItemSell *item = new ItemSell(this);
item->getSale(id);
item->exec();
}
To copy to clipboard, switch view to plain text mode
In this code, if ItemSell is a modal dialog (which it seems to be, since you are calling exec()), then you do not need to create a new one on the heap (using new), you should simply do this:
void Store::showItem()
{
int id = ui->lstSells->model()->index(m_ind.row(), 0).data().toInt();
ItemSell item(this);
item.getSale(id);
item.exec();
}
void Store::showItem()
{
int id = ui->lstSells->model()->index(m_ind.row(), 0).data().toInt();
ItemSell item(this);
item.getSale(id);
item.exec();
}
To copy to clipboard, switch view to plain text mode
The exec() statement causes the dialog to block until the user clicks the OK button, then the ItemSell instance will automatically go away as the showItem() method exits scope. The way you have it written now, you have a memory leak - the ItemSell instances you are creating do not get deleted when the showItem method() exits, but since you aren't saving the pointer anywhere, you have no way to get rid of it later. Not until the Store instance is finally destroyed (when your program exits) do the ItemSell instances it owns (because you set the parent to "this") get deleted. So if the user of your Store software runs the program for weeks or months without ever exiting, eventually their computer will use up all the available memory and your program will probably crash.
Bookmarks