Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED][Qt5.2] Get selected item from QTreeWidget and print selected item
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sharon_obl82
    wrote on last edited by
    #1

    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]

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      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

      Greetz, Jeroen

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved