Tuesday, 23 May 2023

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

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.



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

No comments:

Post a Comment