PySide6: How to clear the values of all QPlainTextEdit and QComboBox elements after inserting data into a database?

Question:

Hy, i want to clear all qtextedit,qcombobox etc.., when a product is inserted in database,but i dont know, how to do it.
Right now this is my function

 def commit(self):
   
    self.inserebd()
    tree_data=self.dadostree()
    self.contarserie()
 

    sql = """INSERT INTO "Teste"("DataEntrada","Código de Barras","Numero de    serie","Categoria","Marcasss","Modelo","Fornecedores","Estado","Projeto","Valor/Uni","Quantidade")       VALUES  (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"""`
    
    for paren_data, children_data in tree_data:   
        
        codigo_barras = paren_data
        if not children_data:
            
            dados=(self.data,codigo_barras,'No',self.idC,self.id,self.modelo,self.idf,self.estado,self.projeto,self.valor,self.quantidade)
            cursor.execute(sql,dados)
            con.commit()
            QtWidgets.QMessageBox.information(self,"Sucesso",f" {self.total_serie} Produtos Inseridos")```
                
   

Tree_data is this:

[('b', ['b']), ('c', ['c'])]

the problem is i dont know were to put this part when i delete all things:

 self.ui.treeWidget.clear()
    self.ui.textmodelo.clear()
    self.ui.textEdit.clear()
    self.ui.textEdit_Data.clear()
    self.ui.textEdit_Preco.clear()
    self.dodo=[] 
    self.ui.comboBox.setCurrentIndex(self.default_item_index)
  self.ui.comboBox_Marca.setCurrentIndex(self.default_item_index)

Because if i put inside the FOR its gonna cause problems when i insert more than one product, but if i put outside the for its gonna cause problems to, because if the insert fails, its gonna delete all data to.

And i just want to delete the textedit, comboBox etc.. when the data is already inserted.
I know its a bit confuse, and its my first time posting a question, but if you have any question ask, im gona try clarify as much as I can.

thank you for the help.

Asked By: Shadow Das Pizzas

||

Answers:

I finaly got it, to resolve my problem i created an numofrows = cursor.rowcount, the rowcount count how many rows were inserted, for those o have the same problem try use it

Answered By: Shadow Das Pizzas
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.