[SOLVED] QTreeWidgetItem question, i don't want all the columns editable.



  • Hi to everyone, i am new in this forum.
    I made a Qtreewidget with items but i don't want to make all the columns editable.

    this is the code @QTreeWidgetItem *treeItem = new QTreeWidgetItem(ui->treeWidget);

    for(int i=0; i<13;i++) {
    treeItem->setTextAlignment(i,Qt::AlignHCenter);
    }

    // QTreeWidgetItem::setText(int column, const QString & text)

    treeItem->setText(Count, a.toUpper());
    treeItem->setFlags(Qt::ItemIsEditable|Qt::ItemIsEnabled|Qt::ItemIsUserCheckable);@

    i have for example a checkbox and if i make double click then it is editable. i found this very bad!
    !http://tinypic.com/r/ddz4vd/8()!



  • Hi again, i have written some more code but the App crashes with SIGABRT signal.

    @void MainWindow::checkValues(QTreeWidgetItem *item, int column) // SLOT emited from SIGNAL itemchanged()
    {
    if(column==4) checkByte(item->text(column),column,item);

    }
    void MainWindow::checkByte(QString byte, int column, QTreeWidgetItem* item)
    {
    bool *ok; QString *b;
    b=&byte;
    int bytetoint = b->toUInt(ok,16);
    if(bytetoint>255) {
    QMessageBox::warning(this,"ERROR","Byte"+byte.setNum(column-3)+" it's higher than 255 or FF");

        item->setText(column,"FF");
    }
    

    }
    @

    When the program exits the checkByte() function crashes, i cannot understand what, i tried to set blocksignal() but its not helps. i thougt that is a infinite loop between itemchanged and item->setText...any ideas ? i am not also sure if i pass correct the item pointer from checkValues to checkByte!


  • Lifetime Qt Champion

    ok is not initialized and why b ?

    @
    bool ok;
    int bytetoint = byte.toUInt(&ok,16);
    @

    By the way, why not use a validator ? That check won't be necessary



  • [quote author="SGaist" date="1416478426"]ok is not initialized and why b ?

    @
    bool ok;
    int bytetoint = byte.toUInt(&ok,16);
    @

    By the way, why not use a validator ? That check won't be necessary[/quote]
    if i use byte.toUint() then the app crashes, do you mean that i need to use byte as pointer and not as object ?
    why you said ok its not intialized? after the conversion it changes to True.


  • Lifetime Qt Champion

    [quote author="xmaze" date="1416477611"]
    @
    void MainWindow::checkByte(QString byte, int column, QTreeWidgetItem* item)
    {
    bool *ok; QString *b; << ok as well as b are uninitialized pointers
    b=&byte;
    int bytetoint = b->toUInt(ok,16); << b->toUint is the same as byte.toUInt
    @
    [/quote]



  • Hi, i understood what you meant, that was my first approach, but the App crashes. i embedded a time elapse with debugging.

    if i made this trick with pointer the i dont have problem. i am running under Fedora 20.

    http://tinypic.com/r/21l0j2b/8


  • Lifetime Qt Champion

    What does a run trough the debugger show you ?



  • Problem found, i made a big mistake but i did not see that.

    My Code was @ bool * ok
    int bytetoint = byte.toUint(ok,16);@

    i change that to @ bool ok
    int bytetoint = byte.toUint(&ok,16);@

    now its working, Thank you a lot, it was a big mistake from me!!


  • Lifetime Qt Champion

    You're welcome !

    Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)



  • Ok, but i have some other questions, need to make a new thread ?

    I want to know in closeEvent() function who is the sender, i have 2 widget and i want to close both of them if one widget is closed.
    but if i have Qdialogbox to ask if the user is sure, then i have a spam annoying dialogbox! the QObject::sender() not working!


  • Lifetime Qt Champion

    Yes, a new thread would be better.

    Because closeEvent is not a slot so there's no sender. A global hint for Qt: when a function has Event in it's name, it's not a slot.


Log in to reply
 

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