Menu

gui freeze when rendering preview QRPT

2022-05-22
2022-05-22
  • Proton Phoenix

    Proton Phoenix - 2022-05-22

    Hi ~~ ^^
    i have a small problem on QRPT
    i am using it just testing o print reports for supermarket ..
    so i have 4 columns and almost 510 rows in QTableView
    the problem is when i try to preview it took almost 6 to 8 seconds to render the preview .. that's not a problem at all but it freezes the GUI of the all software on those seconds ..
    i tried QThread but it didn't fix it

    ~~ just i want a solution of GUI Freeze during rendering the preview

        connect(ui->printbutton,SIGNAL(clicked()),this,SLOT(print()));
    
    void test::print(){
         thread= new QThread();
    
          report=new QtRPT();
          report->setParent(thread);
          report->moveToThread(thread);
          thread->start();
           QString dirpath=QDir::currentPath().append("/release/report/productquantity.XML");
          report->loadReport(dirpath);
    
          QObject::connect(report, SIGNAL(setValue(const int, const QString, QVariant&, const int)),
                               this, SLOT(setValue(int, QString, QVariant&, int)));
          QObject::connect(report, SIGNAL(setDSInfo(DataSetInfo&)),
                            this, SLOT(setDSInfo(DataSetInfo&)));
    
          report->printExec(true,false);
    }
    
     

    Last edit: Proton Phoenix 2022-05-22
  • aliks-os

    aliks-os - 2022-05-22

    hi many thanks for using QtRPT project. Yes the moving instance of QtRpt to the thread is a good solution.

      report=new QtRPT();
          report->moveToThread(thread);
          thread->start();
    

    I think you dont need assign parent to Qtrpt.

     
  • Proton Phoenix

    Proton Phoenix - 2022-05-22

    aliks-os hi bro , thanks for great support , i removed setparent of QtRpt but The same problem
    during rendering ... Software GUI Freeze for 6 to 7 seconds ~!
    is There Any way to fix that?
    i am sure rendering would take time but at least program gui need stay responive to the user~!

     
  • aliks-os

    aliks-os - 2022-05-22

    do you have any warning in Qt Creator when execute print generation?

     
  • Proton Phoenix

    Proton Phoenix - 2022-05-22

    QObject::moveToThread: Cannot move objects with a parent

    this message shows up during rendering
    by the way i removed setparent of qrpt instance

    auto report=new QtRPT;
    QtRpt with no parent
    
     

    Last edit: Proton Phoenix 2022-05-22
  • aliks-os

    aliks-os - 2022-05-22

    looks like the QtRPT is not moved to the QThread

     
  • Proton Phoenix

    Proton Phoenix - 2022-05-22

    yes is there any solution!!? advice

     
  • aliks-os

    aliks-os - 2022-05-22

    yes, it is. I will try to make some small correction in the code. I hope in 1H will be ready

     
  • Proton Phoenix

    Proton Phoenix - 2022-05-22

    aliks-os thank you so much bro , the best support ever i wish the happiest life for you bro thank you <3
    if you fix it where i can find the new code or you will set a new version!

     

    Last edit: Proton Phoenix 2022-05-22
  • aliks-os

    aliks-os - 2022-05-22

    do you use DLL and build from source code?

     
  • Proton Phoenix

    Proton Phoenix - 2022-05-22

    Yes both

     
  • aliks-os

    aliks-os - 2022-05-22

    update from git repo (sourceforge) the file qtrpt.h

     
    ❤️
    1
  • Proton Phoenix

    Proton Phoenix - 2022-05-22

    ok bro i understand it now
    you helped me a lot
    thank you for everything

     
  • aliks-os

    aliks-os - 2022-05-22

    And try run as below

         thread= new QThread(this);
    
          report=new QtRPT();
          report->moveToThread(thread);
    
           QString dirpath=QDir::currentPath().append("/release/report/productquantity.XML");
          report->loadReport(dirpath);
    
          QObject::connect(report, SIGNAL(setValue(const int, const QString, QVariant&, const int)),
                               this, SLOT(setValue(int, QString, QVariant&, int)));
          QObject::connect(report, SIGNAL(setDSInfo(DataSetInfo&)),
                            this, SLOT(setDSInfo(DataSetInfo&)));
    
    QObject::connect(thread, &QThread::started, this, [=]()
        {
        QMetaObject::invokeMethod(report,
                                  "printExec",
                                  Qt::QueuedConnection,
                                  Q_ARG(bool, true),
                                  Q_ARG(bool, false)
                                  );
        });
    
          thread->start();
    
     
  • Proton Phoenix

    Proton Phoenix - 2022-05-22

    thread= new QThread();

       report=new QtRPT();
       report->moveToThread(thread);
    
    QString dirpath=QDir::currentPath().append("/release/report/productquantity.XML");
    

    // QMessageBox::information(this,"W",dirpath.append(""),QMessageBox::Ok);

    report->loadReport(dirpath);

    QObject::connect(report, SIGNAL(setValue(const int, const QString, QVariant&, const int)),
    this, SLOT(setValue(int, QString, QVariant&, int)));
    QObject::connect(report, SIGNAL(setDSInfo(DataSetInfo&)),
    this, SLOT(setDSInfo(DataSetInfo&)));

    QObject::connect(thread, &QThread::started, this, =
    {
    QMetaObject::invokeMethod(report,
    "printExec",
    Qt::QueuedConnection,
    Q_ARG(bool, true),
    Q_ARG(bool, false)
    );
    });

    thread->start();
    report->printExec(true,false);

       trying this
    
       retains those errors
    

    QObject: Cannot create children for a parent that is in a different thread.
    (Parent is QtRPT(0xb0b75c0), parent's thread is QThread(0xc3bf610), current thread is QThread(0x59fa440)
    QObject: Cannot create children for a parent that is in a different thread.
    (Parent is QtRPT(0xb0b75c0), parent's thread is QThread(0xc3bf610), current thread is QThread(0x59fa440)
    QObject::installEventFilter(): Cannot filter events for objects in a different thread.
    QPainter::begin(): Returned false
    QObject::connect: Cannot queue arguments of type 'DataSetInfo&'
    (Make sure 'DataSetInfo&' is registered using qRegisterMetaType().)
    QPainter::resetMatrix: Painter not active
    QPainter::save: Painter not active


    QPainter::restore: Unbalanced save/restore
    QPainter::resetMatrix: Painter not active
    ""
    ~~~

     

    Last edit: Proton Phoenix 2022-05-22
  • aliks-os

    aliks-os - 2022-05-22
    thread->start();
    //report->printExec(true,false);    //<<<<<<<<<Remove this line
    
     
  • Proton Phoenix

    Proton Phoenix - 2022-05-22

    without report->printExec .....

    QMetaObject::invokeMethod: No such method QtRPT::printExec(bool,bool)

     
  • aliks-os

    aliks-os - 2022-05-22

    did you replace qtrpt.h by file from git repo?

     
  • aliks-os

    aliks-os - 2022-05-22
        QMetaObject::invokeMethod(report,
                                  "printExec",
                                  Qt::QueuedConnection,
                                  Q_ARG(bool, true),
                                  Q_ARG(bool, false),
                                   Q_ARG(QString, "")
                                  );
    

    please replace as

     
  • Proton Phoenix

    Proton Phoenix - 2022-05-22

    now after building the latest version with replacing the new file and replacing QMetaObject ...

    QObject: Cannot create children for a parent that is in a different thread.
    (Parent is QtRPT(0xc3a3a90), parent's thread is QThread(0x80a5600), current thread is QThread(0x5a5a2e0)
    QObject::connect: Cannot queue arguments of type 'DataSetInfo&'
    (Make sure 'DataSetInfo&' is registered using qRegisterMetaType().)


    starting evaluate
    QObject::connect: Cannot queue arguments of type 'QVariant&'
    (Make sure 'QVariant&' is registered using qRegisterMetaType().)


    A White Screen and software freeze ...
    using this code

    thread= new QThread(this);
    
       report=new QtRPT();
       report->moveToThread(thread);
    
        QString dirpath=QDir::currentPath().append("/release/report/productquantity.XML";
    
       report->loadReport(dirpath);
    
       QObject::connect(report, SIGNAL(setValue(const int, const QString, QVariant&, const int)),
                            this, SLOT(setValue(int, QString, QVariant&, int)));
       QObject::connect(report, SIGNAL(setDSInfo(DataSetInfo&)),
                         this, SLOT(setDSInfo(DataSetInfo&)));
    
    QObject::connect(thread, &QThread::started, this, [=]()
     {
     QMetaObject::invokeMethod(report,
                                  "printExec",
                                  Qt::QueuedConnection,
                                  Q_ARG(bool, true),
                                  Q_ARG(bool, false),
                                   Q_ARG(QString, "")
                                  );
     });
        thread->start();
    

    if i put thread as parent of QtRPT it works and no white screen
    but the gui freeze and this error show's up constantly

    starting evaluate


    Uncaught exception at line 1 : "SyntaxError: Unexpected token '" Uncaught exception at line 1 : "SyntaxError: Unexpected token'"
    Uncaught exception at line 1 : "SyntaxError: Unexpected token '" Uncaught exception at line 1 : "SyntaxError: Unexpected token'"
    Uncaught exception at line 1 : "SyntaxError: Unexpected token '" Uncaught exception at line 1 : "SyntaxError: Unexpected token'"
    Uncaught exception at line 1 : "SyntaxError: Unexpected token '" Uncaught exception at line 1 : "SyntaxError: Unexpected token'"
    Uncaught exception at line 1 : "SyntaxError: Unexpected token '" Uncaught exception at line 1 : "SyntaxError: Unexpected token'"
    Uncaught exception at line 1 : "SyntaxError: Unexpected token '" Uncaught exception at line 1 : "SyntaxError: Unexpected token'"
    Uncaught exception at line 1 : "SyntaxError: Unexpected token '" Uncaught exception at line 1 : "SyntaxError: Unexpected token'"
    Uncaught exception at line 1 : "SyntaxError: Unexpected token '" Uncaught exception at line 1 : "SyntaxError: Unexpected token'"
    Uncaught exception at line 1 : "SyntaxError: Unexpected token '" Uncaught exception at line 1 : "SyntaxError: Unexpected token'"
    Uncaught exception at line 1 : "SyntaxError: Unexpected token '" Uncaught exception at line 1 : "SyntaxError: Unexpected token'"
    Uncaught exception at line 1 : "SyntaxError: Unexpected token '" Uncaught exception at line 1 : "SyntaxError: Unexpected token'"
    Uncaught exception at line 1 : "SyntaxError: Unexpected token '" Uncaught exception at line 1 : "SyntaxError: Unexpected token'"

     

    Last edit: Proton Phoenix 2022-05-22
  • aliks-os

    aliks-os - 2022-05-22

    I have tested on my side and I am affraid to directly use a QtRPT in a thread, I need to redo a lot in it.

    You can create an intermediate class in which the QtRPT will be located and called. And put this intermediate class in the thread

     
    • Proton Phoenix

      Proton Phoenix - 2022-05-22

      i understand bro , your project is the best of it's kind on qt frameowork
      thank you for your great support
      i will try to do what you told me

       

Log in to post a comment.