Python - QBasicTimer :: start: QBasicTimer can only be used with threads started with QThread

0

I'm trying to implement an animation in my project, this animation starts when you press the self.l_entrar button and it should end when the login window closes and there will be the following:

however I get the following error:

QObject::setParent: Cannot set parent, new parent is in a different thread
QBasicTimer::start: QBasicTimer can only be used with threads started with QThread
QBasicTimer::start: QBasicTimer can only be used with threads started with QThread
QBasicTimer::start: QBasicTimer can only be used with threads started with QThread

The function def anima() , is the one that is responsible for starting the animation, and this function starts in a different thread within the function def setDataPrincipal() , which is linked to the clicked event of self.l_entrar

I am using threads since it was the only way I found that by clicking the enter button, the animation was reproduced.gif in self.label

and this is the result I get:

Principal.py

    from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5 import QtCore
from PyQt5.Qt import QMovie
from PyQt5 import uic
from FirebaseLogin import *
from contraInicio import ContraInicioC
from Principal import PrincipalC
from MostrarDatosTabla import mostararDatos
from CrearFirebase import crear_tabla
from sucursalInicio import sucursal
import sqlite3
import threading

class LoginC(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        uic.loadUi("Interfaz/Login.ui",self)

        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.l_permiso.setAttribute(QtCore.Qt.WA_NoMousePropagation)
        self.l_sucursal.setAttribute(QtCore.Qt.WA_NoMousePropagation)

        self.l_close.clicked.connect(self.close)

        self.contraseña = ContraInicioC()
        self.principal = PrincipalC()
        self.l_entrar.clicked.connect(self.anima)
        self.l_permiso.currentIndexChanged.connect(lambda:self.cambioPermiso(self.l_permiso.currentText()))
        self.l_permiso.setCurrentText("Caja")
        self.suc = sucursal
        self.l_sucursal.setCurrentText(self.suc)
        #self.principal.pc_fecha.setDate(QtCore.QDate.currentDate())



    @QtCore.pyqtSlot(str)
    def cambioPermiso(self,permiso):
        if permiso == "Administrador":

            self.l_sucursal.setEnabled(True)
        else:

            self.l_sucursal.setEnabled(False)
    def anima(self):
        self.movie = QMovie("nueva.gif")
        self.label.setMovie(self.movie)
        self.movie.start()
        t = threading.Thread(target=self.setDataPrincipal)
        t.start()
    def setDataPrincipal(self):
        self.estado = 0
        fechaActual = QtCore.QDate.currentDate().toPyDate()

        ref = db.reference("/"+str(fechaActual))
        ret = ref.get()

        if ret == None:
            print("creada")
            crear_tabla(str(fechaActual))
            self.estado = 0
            if self.l_permiso.currentIndex()==1:
                self.principal.pc_sucursal.setEnabled(False)
                self.principal.pc_fecha.setDate(QtCore.QDate.currentDate())
                self.principal.pc_sucursal.setCurrentText(self.l_sucursal.currentText())
                self.principal.show()

            else:
                print("value")
                #self.contraseña.datos(self.l_permiso.currentText(), "Matutino", self.l_sucursal.currentText(),self.estado,self.principal.p_referencia)
                self.contraseña.permiso = self.l_permiso.currentText()
                self.contraseña.turno = "Matutino"
                self.contraseña.sucursal = self.l_sucursal.currentText()
                self.contraseña.estado = self.estado
                self.contraseña.referencia = self.principal.p_referencia
                self.contraseña.show()
        else:
            self.estado =1
            print("actualizada")
            #mostararDatos(str(fechaActual),self.l_sucursal.currentText(),"Matutino",self.principal.saldo,self.principal.tablaM,self.principal.inventario,self.principal.p_referencia)

            if self.l_permiso.currentIndex()==1:
                self.principal.pc_sucursal.setEnabled(False)
                self.principal.pc_fecha.setDate(QtCore.QDate.currentDate())
                self.principal.pc_sucursal.setCurrentText(self.l_sucursal.currentText())
                self.principal.show()

            else:

                #self.contraseña.datos(self.l_permiso.currentText(), "Matutino", self.l_sucursal.currentText(),self.estado,self.principal.p_referencia)
                self.contraseña.permiso = self.l_permiso.currentText()
                self.contraseña.turno = "Matutino"
                self.contraseña.sucursal = self.l_sucursal.currentText()
                self.contraseña.estado = self.estado
                self.contraseña.referencia = self.principal.p_referencia
                self.contraseña.show()


        self.principal.o_sucursal.setText(self.l_sucursal.currentText())
        self.principal.o_turno.setText("Matutino")
        self.principal.o_permiso.setText(self.l_permiso.currentText())
        #self.principal.pc_sucursal.setCurrentText(self.l_sucursal.currentText())
        #self.principal.pc_fecha.setDate(QtCore.QDate.currentDate())
        self.close()

    def mousePressEvent(self,event):

        if event.button() == QtCore.Qt.LeftButton:
            self.dragPosition = event.globalPos() - self.frameGeometry().topLeft()
            event.accept()


    def mouseMoveEvent(self,event):
        if event.buttons() == QtCore.Qt.LeftButton:
            self.move(event.globalPos() - self.dragPosition)
            event.accept()

app = QApplication([])
l = LoginC()
l.show()
app.exec_()

ARCHIVO.UI

<?xml version="1.0" encoding="UTF-8"?>
        <ui version="4.0">
         <class>MainWindow</class>
         <widget class="QMainWindow" name="MainWindow">
          <property name="geometry">
           <rect>
            <x>0</x>
            <y>0</y>
            <width>650</width>
            <height>370</height>
           </rect>
          </property>
          <property name="windowTitle">
           <string>MainWindow</string>
          </property>
          <property name="styleSheet">
           <string notr="true">background:url(Imagenes/escalado.jpg);
        background-position:center;
        background-repeat:none;</string>
          </property>
          <widget class="QWidget" name="centralwidget">
           <widget class="QPushButton" name="l_close">
            <property name="geometry">
             <rect>
              <x>620</x>
              <y>0</y>
              <width>31</width>
              <height>23</height>
             </rect>
            </property>
            <property name="font">
             <font>
              <pointsize>9</pointsize>
              <weight>75</weight>
              <bold>true</bold>
             </font>
            </property>
            <property name="styleSheet">
             <string notr="true">QPushButton#l_close{
        background:none;
        border:0px;
        color:grey;
        }
        QPushButton#l_close:hover{
        color:red;
        }</string>
            </property>
            <property name="text">
             <string>X</string>
            </property>
           </widget>
           <widget class="QPushButton" name="l_entrar">
            <property name="geometry">
             <rect>
              <x>550</x>
              <y>330</y>
              <width>75</width>
              <height>22</height>
             </rect>
            </property>
            <property name="styleSheet">
             <string notr="true">QPushButton#l_entrar{
        background:#41CD52;
        border:0px;
        color:white;
        }
        QPushButton#l_entrar:pressed{
        border-bottom:2px solid green;
        }
        </string>
            </property>
            <property name="text">
             <string>Entrar</string>
            </property>
           </widget>
           <widget class="QComboBox" name="l_sucursal">
            <property name="enabled">
             <bool>false</bool>
            </property>
            <property name="geometry">
             <rect>
              <x>440</x>
              <y>330</y>
              <width>69</width>
              <height>22</height>
             </rect>
            </property>
            <property name="styleSheet">
             <string notr="true">QComboBox#l_sucursal{
        background:none;
        border:0px;
        border-bottom: 1px solid lightblue;
        color:#05839C;
        }


        QComboBox QAbstractItemView
        {
            border:0px;
            background:white;
            color: grey;

        }
        QComboBox#l_sucursal::drop-down
        {
             subcontrol-origin: padding;
             subcontrol-position: top right;
             width: 15px;
             color: white;
             border-left-width: 0px;
             border-left-color: darkgray;
             border-left-style: solid; /* just a single line */
             border-top-right-radius: 3px; /* same radius as the QComboBox */
             border-bottom-right-radius: 3px;
             padding-left: 10px;
         }</string>
            </property>
            <item>
             <property name="text">
              <string>Exxe 1</string>
             </property>
            </item>
            <item>
             <property name="text">
              <string>Exxe 3</string>
             </property>
            </item>
           </widget>
           <widget class="QLabel" name="lsucursal">
            <property name="geometry">
             <rect>
              <x>380</x>
              <y>330</y>
              <width>51</width>
              <height>22</height>
             </rect>
            </property>
            <property name="styleSheet">
             <string notr="true">color:grey;
        background:none;</string>
            </property>
            <property name="text">
             <string>Sucursal:</string>
            </property>
           </widget>
           <widget class="QLabel" name="la">
            <property name="geometry">
             <rect>
              <x>220</x>
              <y>330</y>
              <width>51</width>
              <height>22</height>
             </rect>
            </property>
            <property name="styleSheet">
             <string notr="true">color:grey;
        background:none;</string>
            </property>
            <property name="text">
             <string>Permisos</string>
            </property>
           </widget>
           <widget class="QComboBox" name="l_permiso">
            <property name="geometry">
             <rect>
              <x>268</x>
              <y>330</y>
              <width>91</width>
              <height>22</height>
             </rect>
            </property>
            <property name="styleSheet">
             <string notr="true">QComboBox#l_permiso{
        background:none;
        border:0px;
        border-bottom: 1px solid lightblue;
        color:#05839C;
        }


        QComboBox QAbstractItemView
        {
            border:0px;
            background:white;
            color: grey;

        }
        QComboBox#l_permiso::drop-down
        {
             subcontrol-origin: padding;
             subcontrol-position: top right;
             width: 15px;
             color: white;
             border-left-width: 0px;
             border-left-color: darkgray;
             border-left-style: solid; /* just a single line */
             border-top-right-radius: 3px; /* same radius as the QComboBox */
             border-bottom-right-radius: 3px;
             padding-left: 10px;
         }</string>
            </property>
            <item>
             <property name="text">
              <string>Administrador</string>
             </property>
            </item>
            <item>
             <property name="text">
              <string>Caja</string>
             </property>
            </item>
           </widget>
           <widget class="QLabel" name="label">
            <property name="geometry">
             <rect>
              <x>110</x>
              <y>110</y>
              <width>181</width>
              <height>141</height>
             </rect>
            </property>
            <property name="text">
             <string/>
            </property>
           </widget>
          </widget>
         </widget>
         <resources/>
         <connections/>
        </ui>
    
asked by Mystic_Force 18.10.2018 в 19:53
source

0 answers