0

I have a problem.
I have 2 QTextEdit fields : value & name.
When I push the button i create QTableWidgetItems with the value from "value" and "name".
But now I will check if the name alredy exists.
But I don't know, with " findItems " ? with contain's ?
Tabelle extends from QWidget in the header.
I'am an c++/ QT Beginner and have no idea as I do that such.
PS: I'am speaking Germany, so you can answer in Germany, my English isn't very good ;D Thank you :)

void Tabelle::pushButtonClicked() :

    strname = ( txtname ->text ());
    strvalue = ( txtvalue ->text ());

The textfields to Strings.

Put the vlaue in Items:

QTableWidgetItem * valueitem = new QTableWidgetItem(0);
valueitem->setText(strvalue);
QTableWidgetItem * nameitem = new QTableWidgetItem(0);
nameitem->setText(strname);

New row :

if (  cou >coucount )
    {table->insertRow(table->rowCount());}
    table->setItem( cou,1, valueitem );
    table->setItem( cou, 0,  nameitem); cou++
Bryan Chen
  • 45,816
  • 18
  • 112
  • 143
thelittlePanda
  • 101
  • 2
  • 10

1 Answers1

1

You can use QList QTableWidget::findItems(const QString & text, Qt::MatchFlags flags) const.

As the doc says: Finds items that matches the text using the given flags.

Try the following code:

QList<QTableWidgetItem *> ItemList = Table->findItems("TestName", Qt::MatchExactly); 
cout<< "Count:" << ItemList.count() << endl;   
Matthias
  • 463
  • 1
  • 7
  • 12
  • Thanks you for the fast answer. must outside the method – thelittlePanda Jun 30 '14 at 07:02
  • Hauptsache es hilft :) – Matthias Jun 30 '14 at 07:04
  • " QList ItemList = Table->findItems("TestName", Qt::MatchExactly); " must outside the method, right ? and in my method i will check if they exist a Item like "TestName" so i wrote if ( ItemList.count() == true ) ? or what returns finditems ? :D When it is false ( it isn't exist ) they shuld add the text .when it's true ( it exist ) the value shuldn't put in the Table – thelittlePanda Jun 30 '14 at 07:10
  • 1
    Haha Okey, forget it, it works :) !!!! perfekt ! Thank you very much I like this forum :) – thelittlePanda Jun 30 '14 at 07:21