Results 1 to 5 of 5

Thread: From extends QTreeWidgetItem emit signal?

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default From extends QTreeWidgetItem emit signal?

    How i can emit a signal from this extendet class? on qt4
    The q4 doc give a method to set a Qt::Unchecked but not a method to grab or emit
    signal from Unchecked or checked.... one way road?


    this compile ok but not work.. why?

    /* Last item of tree !*/
    class QTreeOne : public QObject, public QTreeWidgetItem
    {
    Q_OBJECT
    public:
    QTreeOne(QTreeWidgetItem* parent);
    int db_id;
    void Set_id( int num );
    protected:
    public:
    public slots:
    void Put_works();
    signals:
    void open_db_form(int db_id);
    };

    QTreeOne::QTreeOne(QTreeWidgetItem* parent) :
    QTreeWidgetItem( parent )
    {
    this->setBackgroundColor(0,QColor(237,237, 237, 237));
    this->setFlags(Qt::ItemIsUserCheckable);
    this->setCheckState(0,Qt::Unchecked );
    connect(this, SIGNAL(itemPressed(QTreeOne*,int)),this, SLOT(Put_works()));
    }

    void QTreeOne::Set_id( int num )
    {
    db_id = num;
    }

    void QTreeOne::Put_works()
    {
    if (db_id > 0) {
    emit open_db_form(db_id);
    }
    }

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: From extends QTreeWidgetItem emit signal?

    Quote Originally Posted by patrik08
    connect(this, SIGNAL(itemPressed(QTreeOne*,int)),this, SLOT(Put_works()));
    "this" doesn't emit itemPressed(QTreeOne*,int) signal. You probably wanted to use the QTreeWidget::itemPressed( QTreeWidgetItem*, int ) signal.

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: From extends QTreeWidgetItem emit signal?

    I wand an existing signal or create a mouse event

    from...
    this->setCheckState(0,Qt::Unchecked); or public QObject,


    how i find the next steep from setCheckState => QTreeWidgetItem?


    not work....
    connect(this, SIGNAL(itemPressed(QTreeOne*,int)),this, SLOT(Put_works()));
    connect(this, SIGNAL(itemPressed(QTreeOne*)),this, SLOT(Put_works()));

  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: From extends QTreeWidgetItem emit signal?

    Create the connection in the treewidget, where you create the tree widget items:
    Qt Code:
    1. // TreeOne* item = new TreeOne(...);
    2. connect(this, SIGNAL(itemPressed(QTreeWidget*,int)), item, SLOT(Put_works()));
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: From extends QTreeWidgetItem emit signal?

    Super work....
    Pleas send my an e-mail & and your Pay-pal account on form:
    http://ciz.ch/pdf/Ticket_Form.pdf

    I spend 1/2 day to grab signal from QTreeWidgetItem tanks...


    void Shop_Main::Compose_Addo()
    {
    /* addo_tree->clear(); QTreeView QMouseEvent #include <QTreeView><QTreeWidget> */

    addo_tree->clear();
    QStringList countrys = Query_List_Unique(QString( "SELECT DISTINCT land_code FROM %1 order by land_code" ).arg( TABLE_ADDO ));
    QStringListIterator i(countrys);
    while (i.hasNext()) {
    QString coustr = i.next().toLocal8Bit().constData();
    QTreeWidgetItem *cou = new QTreeWidgetItem(addo_tree);
    cou->setText(0,coustr);
    cou->setToolTip (0,tr("Open to Browse."));
    addo_tree->expandItem(cou);
    QStringList paese = Query_List_Unique(QString( "SELECT DISTINCT ort FROM %1 WHERE land_code='%2' order by ort" ).arg( TABLE_ADDO , coustr));
    QStringListIterator o(paese);
    while (o.hasNext()) {
    QString pas = o.next().toLocal8Bit().constData();
    QTreeWidgetItem *paeort = new QTreeWidgetItem(cou);
    paeort->setText(0,pas);
    paeort->setToolTip (0,tr("Open to Browse."));
    paeort->setIcon(0, QIcon(QString::fromUtf8(":/img/img/folder.png")));
    resultMap relist = Query_Qmap_Report(QString( "SELECT firma, name, id FROM %1 WHERE ort='%2' order by name" ).arg( TABLE_ADDO , pas));
    resultMap::Iterator it;
    for ( it = relist.begin(); it != relist.end(); ++it ) {
    QStringList roxe = it.value();
    int dbid;
    QString na = roxe.at(0).toLocal8Bit().constData();
    QString nb = roxe.at(1).toLocal8Bit().constData();
    QString inte = roxe.at(2).toLocal8Bit().constData();
    if (is_numeric(inte)) {
    bool ok;
    dbid = inte.toInt(&ok);
    } else {
    dbid = 0;
    }
    QString daten =QString("[%1 %2]" ).arg(na , nb );
    QTreeOne *sigle = new QTreeOne(paeort);
    sigle->Set_id(dbid,daten);
    connect(addo_tree, SIGNAL(itemActivated(QTreeWidgetItem*,int)), sigle, SLOT(Put_works()));
    QApplication:rocessEvents();
    }
    }
    }
    }

    svn co http://ciz.ch/svnciz/forms_shop/ test
    cd test && qmake && make

Similar Threads

  1. how to emit signal in a static function ?
    By cxl2253 in forum Qt Programming
    Replies: 32
    Last Post: 7th July 2016, 21:36
  2. emit qt signal is very slow how it can be optimized?
    By sawerset in forum Qt Programming
    Replies: 8
    Last Post: 30th December 2008, 09:21
  3. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 07:16
  4. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  5. how to know which button emit the signal?
    By coder1985 in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2008, 14:26

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.