I guess you need to replace two obsolete lines:
table->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
table->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
with the following Qt 5 code:
table->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
table->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);