Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Signals and slots without a signal



  • Hi,
    I have so far only created a neat looking GUI,
    tabbed windows,
    slider,dial and plot in one window and
    textlog in the other.

    I click on a start button to start simulations; The simulation runs every 2 ms, i need to update the graphs and sliders only every 100 ms. How do I signal the change?

    How do I even refer to the slider (compression) in the overallPerformance widget of the cprData frame?
    @<?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>Widget</class>
    <widget class="QWidget" name="Widget">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>Widget</string>
    </property>
    <widget class="QTabWidget" name="sessionData">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>401</width>
    <height>301</height>
    </rect>
    </property>
    <property name="currentIndex">
    <number>0</number>
    </property>
    <widget class="QWidget" name="cprData">
    <attribute name="title">
    <string>CPR Performance</string>
    </attribute>
    <widget class="QFrame" name="overallPerformance">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>120</width>
    <height>80</height>
    </rect>
    </property>
    <property name="frameShape">
    <enum>QFrame::StyledPanel</enum>
    </property>
    <property name="frameShadow">
    <enum>QFrame::Raised</enum>
    </property>
    <property name="lineWidth">
    <number>5</number>
    </property>
    <widget class="QPushButton" name="start">
    <property name="geometry">
    <rect>
    <x>20</x>
    <y>10</y>
    <width>75</width>
    <height>23</height>
    </rect>
    </widget>
    </widget>
    <widget class="QFrame" name="compression">
    <property name="geometry">
    <rect>
    <x>120</x>
    <y>0</y>
    <width>131</width>
    <height>80</height>
    </rect>
    </property>
    <widget class="QSlider" name="compressionDepth">

    QSlider::handle:vertical {
    height: 10px;
    background: maroon;
    margin: 0 -4px; /* expand outside the groove */
    }
    </widget>
    <widget class="QLabel" name="depth">
    </widget>
    <widget class="QDial" name="compressionRate">
    <property name="geometry">
    <rect>
    <x>70</x>
    <y>10</y>
    <width>41</width>
    <height>51</height>
    </rect>
    </property>
    </widget>
    <widget class="QLabel" name="rate">
    </widget>
    </widget>
    <widget class="QFrame" name="ventilation">
    <property name="geometry">
    <rect>
    <x>260</x>
    <y>0</y>
    <width>131</width>
    <height>80</height>
    </rect>
    </property>
    <property name="frameShape">
    <enum>QFrame::StyledPanel</enum>
    </property>
    <property name="frameShadow">
    <enum>QFrame::Raised</enum>
    </property>
    </widget>
    <widget class="QFrame" name="graphs">
    <property name="geometry">
    <rect>
    <x>-1</x>
    <y>89</y>
    <width>391</width>
    <height>181</height>
    </rect>
    </property>
    <property name="frameShape">
    <enum>QFrame::StyledPanel</enum>
    </property>
    <property name="frameShadow">
    <enum>QFrame::Raised</enum>
    </property>
    </widget>
    </widget>
    <widget class="QWidget" name="sessionLog">
    <attribute name="title">
    <string>Session Log</string>
    </attribute>
    <widget class="QFrame" name="frame_5">
    <property name="geometry">
    <rect>
    <x>-1</x>
    <y>-1</y>
    <width>391</width>
    <height>271</height>
    </rect>
    </property>
    <property name="frameShape">
    <enum>QFrame::StyledPanel</enum>
    </property>
    <property name="frameShadow">
    <enum>QFrame::Raised</enum>
    </property>
    </widget>
    </widget>
    </widget>
    </widget>
    <layoutdefault spacing="6" margin="11"/>
    <resources/>
    <connections>
    <connection>
    <sender>Widget</sender>
    <signal>objectNameChanged(QString)</signal>
    <receiver>rate</receiver>
    <slot>setText(QString)</slot>
    <hints>
    <hint type="sourcelabel">
    <x>199</x>
    <y>149</y>
    </hint>
    <hint type="destinationlabel">
    <x>212</x>
    <y>89</y>
    </hint>
    </hints>
    </connection>
    </connections>
    </ui>@

    Any direction is much appreciated!

    I need to replace the simulation with hardware interface and the whole GUI to an android tablet eventually.
    Terrifying!

    thanks,
    kpks



  • Did you check the signal & slot documentation. See "link":http://qt-project.org/doc/qt-5/signalsandslots.html.

    You will have to create a class that does the job and comunicates with your QMainWindow or QDialog.

    For the 100ms updates you will need a "QTimer":qt-project.org/doc/qt-5.0/qtcore/qtimer.html. But I don't know if you can go that fast...



  • Hi,
    I have already is set up the QTimer and do the simulation every 2 ms. My confusion is, the variables change every 2ms; What should trigger the slots of slider/dial? Can I set a Integer/Double as a signal source? When the value changes and time > 100ms then update graphs?
    The examples seem to be primarily interaction based, not simulation based like in my case.
    Thanks,
    kpks



  • [quote author="kpks" date="1388084793"] Can I set a Integer/Double as a signal source? When the value changes and time > 100ms then update graphs?
    [/quote]

    Yes, you can do that. But the implementation depends on the program structure you created. For example, you can emit a signal from your simulation object every time a new calculation result is ready. But if you are sure a new calculation result is ready always before your time interval then just update the UI objects every 100ms without checking the values.


Log in to reply