logo
down
shadow

Parent Window Slows down a lot on using SetParent through JNA Java


Parent Window Slows down a lot on using SetParent through JNA Java

By : Wellington Albuquerq
Date : November 15 2020, 06:54 AM
it helps some times When you make a window from one process be parented by a window of another process you are attaching the message queues of those windows.
The game window likely has a message loop that is quite different from a normal GUI app. Almost certainly this game is not very interested in dispatching your window's queued messages in a timely fashion. The game did not expect to be hijacked in this way.
code :


Share : facebook icon twitter icon
Using SetParent freeze the parent window

Using SetParent freeze the parent window


By : PiotrPansky
Date : March 29 2020, 07:55 AM
With these it helps As I just stated, you'll need to create a message pump for your form. Try
code :
Thread thread = new Thread( () =>
{
     var formCover = new FormCover();
     Application.Run(formCover);
});
thread.ApartmentState = ApartmentState.STA;
thread.Start();
How to fix the runtime crash - QObject::setParent: Cannot set parent, new parent is in a different thread?

How to fix the runtime crash - QObject::setParent: Cannot set parent, new parent is in a different thread?


By : raul blanco garcia
Date : March 29 2020, 07:55 AM
I wish this helpful for you There are few articles on internet how to make multithreaded applications in Qt. Best explanation can be found here:
http://blog.debao.me/2013/08/how-to-use-qthread-in-the-right-way-part-1/
QObject::setParent: Cannot set parent, new parent is in a different thread

QObject::setParent: Cannot set parent, new parent is in a different thread


By : Mrmarty
Date : March 29 2020, 07:55 AM
I hope this helps you . Let's be clear. Your code is not working as you intended it to work. That is what the framework is telling you.
code :
MyClass * myClass = new MyClass(classX);
QMetaObject::invokeMethod(myClass, "init", Qt::QueuedConnection);
QtConcurrent::run with MainWindow function, warning message "QObject::setParent: Cannot set parent, new parent is i

QtConcurrent::run with MainWindow function, warning message "QObject::setParent: Cannot set parent, new parent is i


By : Ervins
Date : March 29 2020, 07:55 AM
may help you . You can't be touching any Qt-provided QWidget objects from the worker thread, since most of their methods are not thread-safe.
Instead, a way to tackle this is to do the computations in the worker, and then submit functors that update the state to the main thread. See this answer for details.
code :
void MainWindow::calculation()
{
    postToThread([this]{ progressBar->show(); });
    loadMap();
    integral.clear();
    positions.clear();
    offset.clear();
    lines = 0;
    for(int i=0;i<paths.size();i++)
    {
        if (i == 0)
            lines = countNumberOfLines(paths.at(i));
        auto file = i+1;
        postToThread([this]{
            ui->statusBar->showMessage(
              tr("Processing file %1 of %2").arg(file).arg(paths.size()));
        });
        calculateIntegral(paths.at(i));
        postToThread([this]{
          offset.push_back(ui->tableWidget->item(i,1)->text().toDouble());
        });
    }
    makePositionVector();

    postToThread([this]{
      plotData(ui->customPlot);
      ui->export_pb->setEnabled(true);
      progressBar->hide();
      ui->statusBar->showMessage("Done",3000);
    });
}
class Computation : public QObject {
  Q_OBJECT
  void work() {
    Data data;
    ... // updates data
    emit finished(data);
  }
public:
  Q_SLOT void compute() {
    QtConcurrent::run(&Worker::work, this);
  }
  Q_SIGNAL void finished(Data data);
};
class Computation : public QObject {
  Q_OBJECT
  bool m_active { false };
  Data m_data;
  void work() {
    ... // updates m_data
    m_active = false;
  }
public:
  Q_SLOT void compute() {
    m_active = true;
    QtConcurrent::run(&Worker::work, this);
  }
  const Data & data() const {
    Q_ASSERT(! m_active);
    return m_data;
  }
};
  QVector<MyData> data() const {
    Q_ASSERT(! m_active);
   return m_data;
  } 
QObject::setParent: Cannot set parent, new parent is in a different thread in Python

QObject::setParent: Cannot set parent, new parent is in a different thread in Python


By : Karen Guadamuz
Date : March 29 2020, 07:55 AM
Any of those help First, do not modify the code generated by Qt Designer as PyQt recommends, instead create another class that inherits from the appropriate widget and use the initial class as an interface.
Going to the point, Qt does not allow the GUI to be updated from another thread directly, in your case the setValue of the QProgressBar is called in the secondary thread causing the painting to be made in the secuandario thread so Qt complains that it is not guaranteed operation (for example in your case it does not generate problems apparently but Qt does not guarantee that this always happens). The update of the GUI from other threads must be indirectly, which can be through signals, QEvent, QMetaObject::invokeMethod, etc. In this case I will use the signals:
code :
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
import thread_for_audio_record
import time


class FW(object):
    def f_w(self, window):
        self.window = window
        self.window.setObjectName("Test")
        self.window.resize(1054, 700)
        self.window.setStyleSheet("background-color: rgb(180, 180, 180);")
        self.central_widget = QtWidgets.QWidget(self.window)
        self.central_widget.setObjectName("centralwidget")
        self.horizontal_layout = QtWidgets.QHBoxLayout(self.central_widget)
        self.horizontal_layout.setObjectName("horizontalLayout")
        spacer_item = QtWidgets.QSpacerItem(129, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontal_layout.addItem(spacer_item)
        self.vertical_layout = QtWidgets.QVBoxLayout()
        self.vertical_layout.setObjectName("verticalLayout")
        spacer_item_1 = QtWidgets.QSpacerItem(128, 13, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.vertical_layout.addItem(spacer_item_1)
        self.label_utterance = QtWidgets.QLabel(self.central_widget)
        font = QtGui.QFont()
        font.setPointSize(15)
        font.setBold(True)
        font.setBold(True)
        font.setWeight(75)
        self.label_utterance.setFont(font)
        self.label_utterance.setAlignment(QtCore.Qt.AlignCenter)
        self.label_utterance.setObjectName("label_utterance")
        self.vertical_layout.addWidget(self.label_utterance)
        self.text_edit_utterance = QtWidgets.QTextEdit(self.central_widget)
        self.text_edit_utterance.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.text_edit_utterance.setObjectName("text_edit_utterance")
        self.text_edit_utterance.setReadOnly(True)
        self.text_edit_utterance.setFont(font)
        self.vertical_layout.addWidget(self.text_edit_utterance)
        self.line_edit_message_for_user = QtWidgets.QLineEdit(self.central_widget)
        self.line_edit_message_for_user.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.line_edit_message_for_user.setObjectName("lineEdit")
        self.progressBar = QtWidgets.QProgressBar(self.central_widget)
        self.progressBar.setProperty("value", 0)
        self.progressBar.setObjectName("progressBar")
        self.vertical_layout.addWidget(self.progressBar)
        self.vertical_layout.addWidget(self.line_edit_message_for_user)
        self.push_button_start_recording = QtWidgets.QPushButton(self.central_widget)
        font = QtGui.QFont()
        font.setBold(True)
        font.setWeight(75)
        self.push_button_start_recording.setFont(font)
        self.push_button_start_recording.setStyleSheet("background-color: rgb(85, 170, 0);")
        self.push_button_start_recording.setObjectName("pushButton_start_ recording")
        self.vertical_layout.addWidget(self.push_button_start_recording)
        self.push_button_end_recording = QtWidgets.QPushButton(self.central_widget)
        font = QtGui.QFont()
        font.setBold(True)
        font.setWeight(75)
        self.push_button_end_recording.setFont(font)
        self.push_button_end_recording.setStyleSheet("background-color: rgb(182, 0, 0);")
        self.push_button_end_recording.setObjectName("pushButton_end_recording")
        self.vertical_layout.addWidget(self.push_button_end_recording)
        self.label_status = QtWidgets.QLabel(self.central_widget)
        font = QtGui.QFont()
        font.setBold(True)
        font.setWeight(75)
        self.label_status.setFont(font)
        self.label_status.setObjectName("label_status")
        self.vertical_layout.addWidget(self.label_status)
        self.text_edit_status = QtWidgets.QTextEdit(self.central_widget)
        self.text_edit_status.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.text_edit_status.setObjectName("textEdit_status")
        self.text_edit_status.setReadOnly(True)
        self.vertical_layout.addWidget(self.text_edit_status)
        self.push_button_record_again = QtWidgets.QPushButton(self.central_widget)
        font = QtGui.QFont()
        font.setBold(True)
        font.setWeight(75)
        self.push_button_record_again.setFont(font)
        self.push_button_record_again.setStyleSheet("background-color: rgb(255, 255, 127);")
        self.push_button_record_again.setObjectName("pushButton_record_again")
        self.vertical_layout.addWidget(self.push_button_record_again)
        self.push_button_next_utterance = QtWidgets.QPushButton(self.central_widget)
        font = QtGui.QFont()
        font.setBold(True)
        font.setWeight(75)
        self.push_button_next_utterance.setFont(font)
        self.push_button_next_utterance.setStyleSheet("background-color: rgb(85, 170, 0);")
        self.push_button_next_utterance.setObjectName("pushButton_next_utterance")
        self.vertical_layout.addWidget(self.push_button_next_utterance)
        spacer_item_2 = QtWidgets.QSpacerItem(128, 13, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.vertical_layout.addItem(spacer_item_2)
        self.horizontal_layout.addLayout(self.vertical_layout)
        spacer_item_3 = QtWidgets.QSpacerItem(128, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontal_layout.addItem(spacer_item_3)
        self.window.setCentralWidget(self.central_widget)
        self.menubar = QtWidgets.QMenuBar(self.window)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1054, 21))
        self.menubar.setObjectName("menubar")
        self.window.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(self.window)
        self.statusbar.setObjectName("statusbar")
        self.window.setStatusBar(self.statusbar)
        self.retranslate_ui(self.window)
        QtCore.QMetaObject.connectSlotsByName(self.window)

    def retranslate_ui(self, window):

        _translate = QtCore.QCoreApplication.translate
        window.setWindowTitle(_translate("Utterance Recording", "Altran Audio Manager"))
        self.label_utterance.setText(_translate("Utterance Recording", "Test"))
        self.line_edit_message_for_user.setText(_translate("Utterance Recording", "Test."))
        self.text_edit_utterance.setText(_translate("utterance_parsing", ('Test')))
        self.push_button_start_recording.setText(_translate("Utterance Recording", "Start Recording"))
        self.push_button_end_recording.setText(_translate("Utterance Recording", "End Recording"))
        self.label_status.setText(_translate("Utterance Recording", "Test"))
        self.push_button_record_again.setText(_translate("Utterance Recording", "Test"))
        self.push_button_next_utterance.setText(_translate("Utterance Recording", "Test"))


class MainWindow(QtWidgets.QMainWindow, FW):
    progressChanged = QtCore.pyqtSignal(int)

    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.threadpool = QtCore.QThreadPool()
        self.f_w(self)
        self.push_button_start_recording.clicked.connect(self.start_button_func)
        self.progressChanged.connect(self.progressBar.setValue)

    def inside_thread(self):
        percentage = 0
        while percentage < 120:
            percentage = percentage + 20
            time.sleep(0.2)
            self.progressChanged.emit(percentage)

    def start_button_func(self):
        self.worker = thread_for_audio_record.Worker(self.inside_thread)
        self.threadpool.start(self.worker)


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())
Related Posts Related Posts :
  • How to write generic Java API without method Overloading
  • Java Serialization / Deserialization of an ArrayList works only on first program execution
  • Conway's Game of Life's rules dont apply properly
  • call a java method when Click on a html button without using javascript
  • Why does SSLSocketFactory.createSocket returns a Socket instead of SSLSocket?
  • How to schedule a task in Tomcat
  • compare two pdf files (approach) using java
  • What is the use of allowCoreThreadTimeout( ) in ThreadPoolExecutor?
  • Describe the Strategy Design Pattern in Java?
  • MongoDB too many open connections
  • Issue with generate JAXB classes with value constructors
  • Moving from one frame to another in java swing
  • Get a thread by Id
  • how to open front camera and back camera at same time?
  • Messed up with Java Declaration
  • Extracting chart in EXcel as image using java
  • How to get latitude and longitude in Android phone?
  • Do GC pauses and kill -STOP produce the same behavior?
  • Android HTML.ImageGetter Images resized
  • The way to instantiate map<String, List<String>> in Java
  • Java Making objects move while buttons held
  • Androidx Navigation View - `setNavigationItemSelectedListener` Doesn't Work
  • after compiling code JFrame does not appear
  • Netbeans project, JFrames ran from the main JFrame close all JFrames in project
  • Square Retrofit Client: How to enable/disable followRedirects? How to intercept redirect URL?
  • Java Circular Reference - Can’t Compile
  • Mouse click on specific time JAVA
  • android 4 onCreateDialog return type incompatible when overriding
  • Java Implementation of Oracle's DBMS_UTILITY.GET_HASH_VALUE Function
  • javac cannot be run, and furthermore does not seem installed
  • Function to obtain a thread given its ID
  • Java File path to Executable has spaces
  • Minimum Oracle Java VM heap memory setting?
  • Elegant way to create one of a large number of classes
  • Java fx binding styles
  • Summing weights based on string in large file
  • Android ListView setOnItemClickListener not working
  • How is the Java Bootstrap Classloader loaded?
  • Check object is blank
  • Add image between text in JEditorPane
  • Java POI Excel creating new column and new rows
  • NullPointerException when managing bean with Spring+JSF(Primefaces)
  • Content autocomplete in spring tool suite 4
  • Super Noob Help ~ MouseEvent/Frame
  • Making one project with dependencies stand-alone in Eclipse (Java)
  • Jsoup- getting certain attributes from website
  • MongoDB, how to make a link between collections with JAVA code
  • Overriding an abstract method means class abstract class or not in java?
  • Bukkit teleport - nullPointerException
  • How to check if a Float variable is negative in java
  • Servlet: Cannot forward after response has been committed
  • sql query to select a specific cell in excel
  • How to make new picture when mouse dragged in java
  • Use Constants interface in GWT Project
  • Setting size of a JPanel in GroupLayout
  • Construct a map from two equal size arrays
  • Implementing Read-Write Locks with Double-Checked Locking
  • Disable NO_BUTTON from JOptionPane Java if a condition is true
  • UDP multiple socket
  • Android Threading: This Handler class should be static or leaks might occur
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org