Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Signals and slots in xml coding

Signals and slots in xml coding

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ebonygeek
    wrote on last edited by
    #1

    I have been playing with Qt for some months now. I am teaching myself through coding and recreating code in various versions; QML, XML, C++, Gui.

    This approach is giving me a lot of insight.
    But I am stuck, The code below is mainly to do it all in xml. But I can't get my signals and slots to work. Everything looks fine to me and I am thinking I have missed something.

    @

    <ui version="4.0">
    <class>enTry1</class>
    <widget class="QMainWindow" name="enTry1">
    <property name="geometry" >
    <rect>
    <x>0</x>
    <y>0</y>
    <width>500</width>
    <height>200</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>All xml signals and slots example</string>
    </property>
    <widget class="QWidget" name="centralWidget">
    <widget class="QPushButton" name="pushButton">
    <property name="geometry">
    <rect>
    <x>70</x>
    <y>75</y>
    <width>75</width>
    <height>23</height>
    </rect>
    </property>
    <property name="text">
    <string>Pushbutton</string>
    </property>
    </widget>
    <widget class="QPushButton" name="pushButton_2">
    <property name="geometry">
    <rect>
    <x>70</x>
    <y>125</y>
    <width>75</width>
    <height>23</height>
    </rect>
    </property>
    <property name="text">
    <string>Pushbutton_2</string>
    </property>
    </widget>
    <widget class="QLabel" name="label">
    <property name="geometry">
    <rect>
    <x>80</x>
    <y>40</y>
    <width>46</width>
    <height>13</height>
    </rect>
    </property>
    <property name="text">
    <string>TextLabel</string>
    </property>
    </widget>
    </widget>

        <widget class="QMenuBar" name="menuBar">
            <property name="geometry">
                <rect>
                    <x>0</x>
                    <y>0</y>
                    <width>400</width>
                    <height>21</height>
                </rect>
            </property>
        </widget>
        <widget class="QToolBar" name="mainToolBar">
            <attribute name="toolBarArea">
                <enum>TopToolBarArea</enum>
            </attribute>
            <attribute name="toolBarBreak">
                <bool>false</bool>
            </attribute>
        </widget>
        <widget class="QStatusBar" name="statusBar" />
    
    </widget>
    
    <layoutDefault spacing="6" margin="11" />
    <resources/>
    <connections>
        <connection>
            <sender>pushButton</sender>
            <signal>clicked()</signal>
            <receiver>enTry1</receiver>
            <slot>button1pressed()</slot>
            <hints>
                <hint type="sourcelabel">
                    <x>113</x>
                    <y>138</y>
                </hint>
                <hint type="destinationlabel">
                    <x>207</x>
                    <y>136</y>
                </hint>
            </hints>
        </connection>
        <connection>
            <sender>pushButton_2</sender>
            <signal>clicked()</signal>
            <receiver>enTry1</receiver>
            <slot>button2pressed()</slot>
            <hints>
                <hint type="sourcelabel">
                    <x>127</x>
                    <y>199</y>
                </hint>
                <hint type="destinationlabel">
                    <x>206</x>
                    <y>183</y>
                </hint>
            </hints>
        </connection>
    </connections>
    <slots>
        <slot>button1pressed()</slot>
        <slot>button2pressed()</slot>
    </slots>
    

    </ui>
    @

    To give more info the code runs just nothing when buttons are pressed. The errors say;

    QObject::connect: No such slot QLabel::button1pressed() in ./ui_entry1.h:69
    QObject::connect: (sender name: 'pushButton')
    QObject::connect: (receiver name: 'label')
    QObject::connect: No such slot enTry1::button2pressed() in ./ui_entry1.h:70
    QObject::connect: (sender name: 'pushButton_2')
    QObject::connect: (receiver name: 'enTry1')

    Any suggestions....??

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      Hi,

      [quote author="ebonygeek" date="1374271313"]
      QObject::connect: No such slot QLabel::button1pressed() in ./ui_entry1.h:69
      QObject::connect: (sender name: ‘pushButton’)
      QObject::connect: (receiver name: ‘label’)
      [/quote]

      I don't know how did you create the connection, but as you can see in the documentation of QLabel, there is no slot called button1pressed() in QLabel.

      http://qt-project.org/doc/qt-5.1/qtwidgets/qlabel.html

      [quote author="ebonygeek" date="1374271313"]
      QObject::connect: No such slot enTry1::button2pressed() in ./ui_entry1.h:70
      QObject::connect: (sender name: ‘pushButton_2’)
      QObject::connect: (receiver name: ‘enTry1’)
      [/quote]

      enTry1 is object name of your custom class MainWindow. You should define a slot called button2pressed() in the class if you want to make this connection works.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved