Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I haven't done too much Qt development recently, but if I remember correctly, you can call <a href="http://doc.qtsoftware.com/4.5/qcoreapplication.html#processEvents" rel="nofollow noreferrer"><code>QApplication::processEvents()</code></a> within your own event loop (instead of starting the Qt main loop through <a href="http://doc.qtsoftware.com/4.5/qapplication.html#exec" rel="nofollow noreferrer"><code>QApplication::exec()</code></a>)</p> <p><strong>Edit:</strong> I have used the opportunity of a slow Sunday morning to test-drive / learn something about <a href="http://www.riverbankcomputing.co.uk/software/pyqt/intro" rel="nofollow noreferrer">PyQt</a> (Python bindings for Qt) and cobbled together a proof-of-concept code below. Replacing the call to <code>QApplication::exec()</code> with a custom event loop based on <code>QApplication::processEvents()</code> <em>seems</em> to work.</p> <p>I have also quickly looked at <a href="http://git.thousandparsec.net/gitweb/gitweb.cgi?p=libtpproto-cpp.git;a=blob;f=tpproto/simpleeventloop.cpp;h=f2e1adf992010ee8ee323738e2722aab7dbcefec;hb=HEAD" rel="nofollow noreferrer"><code>simpleeventloop.cpp</code></a> and <a href="http://git.thousandparsec.net/gitweb/gitweb.cgi?p=tpclient-cpptext.git;a=blob;f=src/main.cpp;h=04cdd3e6a0471e2811142fdcaeb80ee6ecde3cd2;hb=HEAD" rel="nofollow noreferrer"><code>tpclient-cpptext main.cpp</code></a>. From the looks of it, it shoud be fine to just add <code>QApplication::processEvents()</code> somewhere in the main loop of <code>SimpleEventLoop::runEventLoop()</code>. To add it to the main loop, I would probably replace the <code>tv</code> interval for the <code>select()</code> function in <a href="http://git.thousandparsec.net/gitweb/gitweb.cgi?p=libtpproto-cpp.git;a=blob;f=tpproto/simpleeventloop.cpp;hb=ebfc08b322c552d73d34a368cca0623782f8d3f8#l106" rel="nofollow noreferrer">lines <code>106</code> through <code>117</code></a> with</p> <pre><code>tv.tv_sec = 0; tv.tv_usec = 10000; // run processEvents() every 0.01 seconds app-&gt;processEvents(); </code></pre> <p>and change the signature in <a href="http://git.thousandparsec.net/gitweb/gitweb.cgi?p=libtpproto-cpp.git;a=blob;f=tpproto/simpleeventloop.cpp;hb=ebfc08b322c552d73d34a368cca0623782f8d3f8#l89" rel="nofollow noreferrer">line <code>89</code></a> to <code>void SimpleEventLoop::runEventLoop(QApplication *app)</code>. It should than be fine to add your usual Qt stuff to your implementation of the client (your replacement of <code>tpclient-cpptext main.cpp</code>)</p> <p>Looks like a hack, though. I would probably start with something like this to get started. I think that your idea of wrapping <a href="http://www.thousandparsec.net/tp/dev/documents/libtpproto-cpp/html/classTPProto_1_1TPSocket.html" rel="nofollow noreferrer"><code>TPSocket</code></a> and the timer within Qt's respective concepts in order to forward them with the <a href="https://doc.qt.io/qt-5/qabstracteventdispatcher.html" rel="nofollow noreferrer"><code>QAbstractEventDispatcher</code></a> to the <a href="https://doc.qt.io/qt-5/qeventloop.html" rel="nofollow noreferrer"><code>QEventLoop</code></a> is the better long-term solution. It should then be sufficient that your <code>runEventLoop()</code> simply calls <code>QApplication::exec()</code>. But I have never used <code>QAbstractEventDispatcher</code> before, so take my comments for what they are.</p> <pre><code>import sys import time from PyQt4 import QtGui from PyQt4 import QtCore # Global variable used as a quick and dirty way to notify my # main event loop that the MainWindow has been exited APP_RUNNING = False class SampleMainWindow(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QMainWindow.__init__(self) global APP_RUNNING APP_RUNNING = True # main window self.setGeometry(300, 300, 250, 150) self.setWindowTitle('Test') self.statusBar().showMessage('Ready') # exit action (assumes that the exit icon from # http://upload.wikimedia.org/wikipedia/commons/b/bc/Exit.png # is saved as Exit.png in the same folder as this file) exitAction = QtGui.QAction(QtGui.QIcon('Exit.png') ,'Exit' ,self) exitAction.setShortcut('Ctrl+Q') exitAction.setStatusTip('Exit application') self.connect(exitAction ,QtCore.SIGNAL('triggered()') ,QtCore.SLOT('close()')) # main menu menubar = self.menuBar() fileMenu = menubar.addMenu('&amp;File') fileMenu.addAction(exitAction) # toolbar self.toolbar = self.addToolBar('Exit') self.toolbar.addAction(exitAction) # text editor textEdit = QtGui.QTextEdit() self.setCentralWidget(textEdit) #tool tip textEdit.setToolTip('Enter some text') QtGui.QToolTip.setFont(QtGui.QFont('English', 12)) def closeEvent(self, event): reply = QtGui.QMessageBox.question(self ,'Message' ,"Are you sure?" ,QtGui.QMessageBox.Yes ,QtGui.QMessageBox.No) if reply == QtGui.QMessageBox.Yes: event.accept() global APP_RUNNING APP_RUNNING = False else: event.ignore() # main program app = QtGui.QApplication(sys.argv) testWindow = SampleMainWindow() testWindow.show() # run custom event loop instead of app.exec_() while APP_RUNNING: app.processEvents() # sleep to prevent that my "great" event loop eats 100% cpu time.sleep(0.01) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload