[Qgis-developer] Trouble in construct attribute dialog

Jacory jacorygao at outlook.com
Sat Jan 2 23:23:53 PST 2016


Hello everyone.

I’m now working on a personal GIS project, I want to use some features of QGis. Now I meet a wired thing that I can’t initialize the attribute dialog of a vector layer well, I’m writing to you to see if someone can help me. Thanks.

The code is simple, I paste them here

void qgis_dev::openAttributeTableDialog()
{
    QgsVectorLayer* mylayer = qobject_cast<QgsVectorLayer*>( activeLayer() );
    if ( !mylayer ) { return; }
    //qgis_devattrtableDialog* d = new qgis_devattrtableDialog( mylayer, this );
    // d->show();


    QgsVectorLayerCache* lc = new QgsVectorLayerCache( mylayer, mylayer->featureCount() );
    QgsAttributeTableView* tv = new QgsAttributeTableView();
    QgsAttributeTableModel* tm = new QgsAttributeTableModel( lc, this );

    QgsAttributeTableFilterModel* tfm = new QgsAttributeTableFilterModel( new QgsMapCanvas(), tm, tm );

    tfm->setFilterMode( QgsAttributeTableFilterModel::ShowAll );
    tm->loadLayer();
    tv->setModel( tfm );
    tv->show();
}

and the result is like this, there are no attributes in the form, but the feature count is right.



However, when I paste these code into QGis source code and compile the project, I get the right result. I don’t know where I am wrong.


Really hope to get some help.

Thank you!


jacorygao at outlook.com <mailto:jacorygao at outlook.com>
=========================




_______________________________________________
Qgis-developer mailing list
Qgis-developer at lists.osgeo.org
List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160103/8b01b112/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QQ??20160102171248.png
Type: image/png
Size: 9223 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160103/8b01b112/attachment.png>


More information about the Qgis-developer mailing list