[SOLVED][Qt5.2] Get selected item from QTreeWidget and print selected item



  • Hi,

    My code looks like this:
    @@
    TreeMenu::TreeMenu(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::TreeMenu)
    {
    ui->setupUi(this);
    connect(QTreeWidgetItem, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(itemClicked(QTreeWidgetItem *, int)));
    }

    void TreeMenu::itemClicked(QTreeWidgetItem *item, int column)
    {
    qDebug() << "Item Text: " << item->text(column);

    }
    @@

    Compilation error shows "Expected primary expression before ',' token.
    Does anyone know how i can fix this please?
    Thank you

    [edit: added missing coding tags @ SGaist]



  • Hi,
    First rule is to place your code between the 'code @' so it becomes better readable code.
    Second, read the signal/slot documentation!

    The way you want to connect the treewidget to the line edit only sets a new text to the lineedit. It does not open a new window. Should the new window be a dialog that interacts with the user, does it need to be a standalone window that starts a new process or is it only a window to display some data?
    You probably want to catch the doubleClicked signal from the treewidget. In that slot do you thing with the creation of the window etc.
    Store the windows in a QList as mainwindow member variable to keep track of them.
    Hope this helps


  • Lifetime Qt Champion

    Hi,

    To add to Jeroentje@home

    @
    MainWindow lineEdit;

    connect(QTreeWidgetItem, SIGNAL(itemClicked(QTreeWidgetItem *, int)), lineEdit, SLOT(itemClicked(QTreeWidgetItem *, int)));
    @

    doesn't really make sense. You are creating a MainWindow called lineEdit that you don't use and you try to connect a class name.

    That connect statement should be in the constructor of MainWindow and the first argument should be the instance of your QTreeWidget not a class name.

    Hope it helps


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.