Qt4 QTreeWidget with VS2015 x64 win10

125 views Asked by At

I've compiled qt 4.8.6 manually using vs2015 x64 native tools, since there no oficial support for this visual studio version. To avoid compilation errors and add new mkspec i was used this help (How to build Qt 4.8.6 with Visual Studio 2015 without official support?). First found problem is that QTreeWidget does not work correctly: items cant be selected. Simple example shows that after selecting item became deselected instantly.

#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent){
    QTreeWidget* tree = new QTreeWidget;
    QTreeWidgetItem* item1 = new QTreeWidgetItem;
    item1->setText(0, "item1");
    QTreeWidgetItem* item2 = new QTreeWidgetItem;
    item2->setText(0, "item2");
    tree->addTopLevelItem(item1);
    tree->addTopLevelItem(item2);
    this->setCentralWidget(tree);

    connect(tree, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(on_item_change(QTreeWidgetItem *, QTreeWidgetItem *)));
    connect(tree, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(on_item_click(QTreeWidgetItem *, int)));
}

void MainWindow::on_item_change(QTreeWidgetItem *current, QTreeWidgetItem *previous) {
    printf("item changed from %p to %p\n", previous, current);
}

void MainWindow::on_item_click(QTreeWidgetItem * item, int column) {
    std::cout << "item clicked " << item->text(column).toStdString() << "\n";
}

output after several clicks is

item changed from 0000000000000000 to 00000160CEE5E060
item changed from 00000160CEE5E060 to 0000000000000000
item clicked item1
item changed from 0000000000000000 to 00000160CEE5E650
item changed from 00000160CEE5E650 to 0000000000000000
item clicked item2
item changed from 0000000000000000 to 00000160CEE5E060
item changed from 00000160CEE5E060 to 0000000000000000
item clicked item1

Visually it looks like there are no items selected, and current item in tree is NULL. I've tried qt 4.8.7 and got same result. On the latest qt version this example works correctly. So, there is a question: how to avoid this bug? Maybe someone builds qt 4.8 with VS2015 in a different way? Or can it be code mistake?

0

There are 0 answers