Results 1 to 7 of 7

Thread: QTreeWidget SIGNAL

  1. #1
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default QTreeWidget SIGNAL

    QT:4.1.1

    Hello everybody,

    I am trying to call a function by clicking on a item with the signal: itemClicked()
    It happens nothing beim clicking on a item. Can somebody see what is wrong:

    Qt Code:
    1. MainWindow::MainWindow()
    2.  
    3. {
    4. ui.setupUi(this);
    5.  
    6.  
    7. connect(ui.tabellen_cb, SIGNAL(currentIndexChanged (int)), this, SLOT(selectTable()));
    8. connect(ui.actionverbinden, SIGNAL(triggered()), this, SLOT(openLoginDialog()));
    9. connect(ui.actionNeu, SIGNAL(triggered()), this, SLOT(insertNewRow()));
    10. connect(ui.abfrage_btn, SIGNAL(clicked()), this, SLOT(selectTable()));
    11. connect(ui.new_btn, SIGNAL(clicked()), this, SLOT(insertNewRow()));
    12. connect(ui.delete_btn, SIGNAL(clicked()), this, SLOT(deleteRow()));
    13. connect(ui.abfrage_btn, SIGNAL(clicked()), this, SLOT(addItemsToTreeWidget()));
    14.  
    15.  
    16. QTreeWidgetItem *root = new QTreeWidgetItem(ui.tree);
    17. QTreeWidgetItem *tables = new QTreeWidgetItem(root);
    18. connect(ui.tree, SIGNAL(itemClicked (tables,0)), this, SLOT(selectTable()));
    19.  
    20.  
    21. init();
    22.  
    23. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MainWindow::selectTable()
    2. {
    3. /*
    4. QString table = ui.tabellen_cb->currentText();
    5. QSqlTableModel *model = new QSqlTableModel;
    6.   model->setTable(table);
    7.   //So kann man jeder Feld update: OnFiledChange
    8.   model->setEditStrategy(QSqlTableModel::OnFieldChange);
    9.   model->select();
    10.  
    11.  
    12.   ui.tableView->setModel(model);
    13.   ui.tableView->show();
    14.   */
    15. QTreeWidgetItem *root = new QTreeWidgetItem(ui.tree);
    16. root->setIcon(0, QIcon(QString::fromUtf8(":/images/images/database.jpg")));
    17. root->setText(0, "inventar");
    18.  
    19. QTreeWidgetItem *tables = new QTreeWidgetItem(root);
    20. tables->setIcon(0, QIcon(QString::fromUtf8(":/images/images/table.jpg")));
    21. tables->setText(0, "tabellen");
    22. QString table = tables->text(0);
    23. QMessageBox::information(this,"",table);
    24. model->setTable(table);
    25. //So kann man jeder Feld update: OnFiledChange
    26. model->setEditStrategy(QSqlTableModel::OnFieldChange);
    27. model->select();
    28.  
    29.  
    30. ui.tableView->setModel(model);
    31. ui.tableView->show();
    32.  
    33. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MainWindow::addItemsToTreeWidget()
    2. {
    3. ui.tree->clear();
    4. ui.tree->setObjectName(QLatin1String("ui.tree"));
    5. ui.tree->setHeaderLabels(QStringList(tr("database")));
    6. // ui.tree->header()->setResizeMode(QHeaderView::Stretch);
    7.  
    8. QTreeWidgetItem *root = new QTreeWidgetItem(ui.tree);
    9. root->setIcon(0, QIcon(QString::fromUtf8(":/images/images/database.jpg")));
    10. root->setText(0, "inventar");
    11.  
    12. QTreeWidgetItem *tables = new QTreeWidgetItem(root);
    13. tables->setIcon(0, QIcon(QString::fromUtf8(":/images/images/table.jpg")));
    14. tables->setText(0, "tabellen");
    15.  
    16. QSqlQuery select("select * from sysobjects where xtype = 'U' order by name");
    17. while(select.next())
    18. {
    19. QString tabelle = select.value(0).toString();
    20. //new QTreeWidgetItem(tables, tabelle, 0);
    21. QTreeWidgetItem *items = new QTreeWidgetItem(tables);
    22. items->setText(0, tabelle);
    23. items->setIcon(0, QIcon(QString::fromUtf8(":/images/images/table.jpg")));
    24.  
    25. }
    26.  
    27. }
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget SIGNAL

    Qt Code:
    1. connect(ui.tree, SIGNAL(itemClicked (tables,0)), this, SLOT(selectTable()))
    To copy to clipboard, switch view to plain text mode 

    You can't set values in connect statements. You should use types there.

    Try this:
    Qt Code:
    1. connect(ui.tree, SIGNAL(itemClicked (QTreeWidgetItem*,int)), this, SLOT(selectTable()))
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QTreeWidget SIGNAL

    hi wysota!
    It works like this:
    Qt Code:
    1. connect(ui.tree, SIGNAL(itemClicked (QTreeWidgetItem*,int)), this, SLOT(selectTable()))
    To copy to clipboard, switch view to plain text mode 

    But i would like to call "selectTable()" just if i click a item of tables (not root and tables it self, but all items of tables should be able to call my function "selectTable()":
    Qt Code:
    1. .
    2. .
    3. QTreeWidgetItem *root = new QTreeWidgetItem(ui.tree);
    4. root->setIcon(0, QIcon(QString::fromUtf8(":/images/images/database.jpg")));
    5. root->setText(0, "inventar");
    6. QTreeWidgetItem *tables = new QTreeWidgetItem(root);
    7. .
    8. .
    To copy to clipboard, switch view to plain text mode 
    Thats why i tryed:
    Qt Code:
    1. connect(ui.tree, SIGNAL(itemClicked (tables,0)), this, SLOT(selectTable()))
    To copy to clipboard, switch view to plain text mode 

    Is that complex to implement?
    Think DigitalGasoline

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTreeWidget SIGNAL

    You can't use parameter values in SIGNAL macro.
    You need to implement a slot for checking which item was clicked and then call selectTable() if appropriate.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTreeWidget SIGNAL

    Provide a custom slot which checks values of those parameters.

    Qt Code:
    1. void someclass::someslot(QTreeWidgetItem *item, int column){
    2. if(item && column==0) selectTable();
    3. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QTreeWidget SIGNAL

    Hi everybody
    Ok i will do that!
    Is there a possibility to get my selected Item text? I found none function at QTreeWidget and QTreeWidgetItem
    . I found just "text()".
    In QT 3 i could use xx->currentText().

    Its easy to get my selected text or its not possible?
    Think DigitalGasoline

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTreeWidget SIGNAL

    Qt Code:
    1. ui.tree->currentItem()->text()
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTreeWidget clicked signal
    By ^NyAw^ in forum Qt Programming
    Replies: 41
    Last Post: 30th January 2010, 12:42
  2. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 08:16
  3. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 08:04
  4. QTreeWidget fails to emit itemClicked signal.
    By avh in forum Qt Programming
    Replies: 2
    Last Post: 6th June 2008, 19:49
  5. QTreeWidget double click signal
    By Pinco Pallino in forum Newbie
    Replies: 2
    Last Post: 18th November 2006, 17:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.