0

私はQtで数ヶ月遊んでいます。私はさまざまなバージョンでコードをコーディングして再作成することで独学しています。QML、XML、C++、Gui。

このアプローチは私に多くの洞察を与えています。しかし、私は立ち往生しています.以下のコードは主にxmlですべてを行うことです. しかし、シグナルとスロットを機能させることができません。私にはすべて問題ないように見えますが、何かを見逃していると思います。

    <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>

詳細情報を提供するために、ボタンが押されたときにコードは何も実行しません。エラーは言う;

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’)

助言がありますか…。??

4

1 に答える 1

1

http://qt-project.org/doc/qt-5.0/qtdesigner/designer-using-a-ui-file.html

http://qt-project.org/doc/qt-4.8/examples-designer.html

Ui ファイルは次のようにも知られています。

Qt デザイナー フォーム

通常見ている XML は、Qt Designer によって生成されます。生成されたファイルを編集する代わりに、Designer の使用に関するチュートリアルに従います。

xml の例や、qt ドキュメントで xml を編集することの意味は見たことがありません。

とはいえ、現在の問題を把握する最善の方法は、Qt Designer を開き、ボタンとラベルと接続をQMainWindow.xml ファイルに作成し、ui ファイルを生成した後、それを書き込もうとしているファイルと比較することです。手で。

それが役立つことを願っています。

于 2013-07-20T01:48:26.227 に答える