QT Filediaglog erscheint zweimal



  • Hallo!
    Ich habe meine ersten Versuche mit QT3 gemacht.
    Jetzt hab ich so ein File open Dialog implementiert:

    void mainwindow::OpenFile()
    {
       QString FileName = QFileDialog::getOpenFileName(".","*.cfg",this);
       if (!FileName.isEmpty())
          Configuration.Load(FileName);
    }
    

    Jedoch erscheint dieser Dialog nach dem Auswählen des Files noch einmal.
    Erst dann verschwindet er. Die Datei wird aber deim ersten Dialog
    geladen. Drück ich beim zweiten Dialog auf Abbrechen, ist das File
    trotzdem geladen.



  • Du zeigst zu wenig, um den Fehler zu sehen. Der Code scheint ok zu sein. Zeig mal ein Minimalbeispiel, das den Fehler zeigt.



  • Genau so hab ich den Slot in meinem Programm implementiert.
    Das Configuration.load erhält den Dateinamen als Argument und lädt das
    File.
    Ich weiss nicht, was ich sonst noch posten soll.



  • mase schrieb:

    Genau so hab ich den Slot in meinem Programm implementiert.
    Das Configuration.load erhält den Dateinamen als Argument und lädt das
    File.
    Ich weiss nicht, was ich sonst noch posten soll.

    1. Ich seh keine deiner Dateien.
    2. Noch besser ist ein vollständiges kleines Programm, das man selbst laufen lassen kann. Die Arbeit solltest du dir machen, wenn du kompetente Hilfe möchtest.



  • Ok, aber ich denke, die Klasse cConfiguration, von der Configuration ein
    Objekt ist, brauchen wir hier nicht.

    test.cpp

    #include "mainwindow.h"
    #include <qapplication.h>
    
    int main( int argc, char ** argv ) {
       QApplication a( argc, argv );
       mainwindow * mw = new mainwindow();
       mw->setCaption( "Pyromaster" );
       mw->show();
       a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) );
       return a.exec();
    

    window.ui, von ihm hab ich mainwindow abgeleitet

    <!DOCTYPE UI><UI version="3.3" stdsetdef="1">
    <class>Form1</class>
    <widget class="QMainWindow">
        <property name="name">
            <cstring>Form1</cstring>
        </property>
        <property name="geometry">
            <rect>
                <x>0</x>
                <y>0</y>
                <width>600</width>
                <height>480</height>
            </rect>
        </property>
        <property name="caption">
            <string>Form1</string>
        </property>
        <widget class="QLineEdit">
            <property name="name">
                <cstring>LineEditKeyword</cstring>
            </property>
            <property name="geometry">
                <rect>
                    <x>50</x>
                    <y>100</y>
                    <width>121</width>
                    <height>23</height>
                </rect>
            </property>
        </widget>
        <widget class="QSpinBox">
            <property name="name">
                <cstring>SpinBoxValue</cstring>
            </property>
            <property name="geometry">
                <rect>
                    <x>190</x>
                    <y>100</y>
                    <width>32</width>
                    <height>21</height>
                </rect>
            </property>
        </widget>
        <widget class="QLabel">
            <property name="name">
                <cstring>TextLabelValue</cstring>
            </property>
            <property name="geometry">
                <rect>
                    <x>50</x>
                    <y>150</y>
                    <width>121</width>
                    <height>21</height>
                </rect>
            </property>
            <property name="text">
                <string></string>
            </property>
        </widget>
        <widget class="QLabel">
            <property name="name">
                <cstring>textLabel1</cstring>
            </property>
            <property name="geometry">
                <rect>
                    <x>50</x>
                    <y>60</y>
                    <width>212</width>
                    <height>21</height>
                </rect>
            </property>
            <property name="text">
                <string>Enter keyword and value number</string>
            </property>
        </widget>
        <widget class="QPushButton">
            <property name="name">
                <cstring>OK</cstring>
            </property>
            <property name="geometry">
                <rect>
                    <x>260</x>
                    <y>100</y>
                    <width>71</width>
                    <height>21</height>
                </rect>
            </property>
            <property name="text">
                <string>OK</string>
            </property>
        </widget>
    </widget>
    <menubar>
        <property name="name">
            <cstring>MenuBar</cstring>
        </property>
        <item text="&amp;File" name="fileMenu">
            <action name="fileOpenAction"/>
            <action name="fileSaveAction"/>
            <action name="fileSaveAsAction"/>
            <separator/>
            <separator/>
        </item>
    </menubar>
    <toolbars>
    </toolbars>
    <actions>
        <action>
            <property name="name">
                <cstring>fileOpenAction</cstring>
            </property>
            <property name="iconSet">
                <iconset>image0</iconset>
            </property>
            <property name="text">
                <string>Open</string>
            </property>
            <property name="menuText">
                <string>&amp;Open...</string>
            </property>
            <property name="accel">
                <string>Ctrl+O</string>
            </property>
        </action>
        <action>
            <property name="name">
                <cstring>fileSaveAction</cstring>
            </property>
            <property name="iconSet">
                <iconset>image1</iconset>
            </property>
            <property name="text">
                <string>Save</string>
            </property>
            <property name="menuText">
                <string>&amp;Save</string>
            </property>
            <property name="accel">
                <string>Ctrl+S</string>
            </property>
        </action>
        <action>
            <property name="name">
                <cstring>fileSaveAsAction</cstring>
            </property>
            <property name="text">
                <string>Save As</string>
            </property>
            <property name="menuText">
                <string>Save &amp;As...</string>
            </property>
            <property name="accel">
                <string></string>
            </property>
        </action>
    </actions>
    <images>
        <image name="image0">
            <data format="PNG" length="210">89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b0000009949444154388ded94410e85200c445f89c7367f61bc775d2848a42860ffced9548bbe8e13043e1d928177f481a123dc2b34f6f47a3de2b865a8843f4001982a0b3d5f62c58300aa1ad70550449ab9d507a773a8a4ba4f92a2df333c64c63bebbd82e5b8addecbcc7820eb4266c639745dfa80f36faf66c66fa19c3f882fb470ec05cdc0bed07893f68e171492635f686c3eeff6ba3c8fdd366dc4c0452c8781f8080000000049454e44ae426082</data>
        </image>
        <image name="image1">
            <data format="PNG" length="217">89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b000000a049444154388dd5954d0a802010859fd14668e18de662d222bc98376a21b4ac451992c66469e0b7f187f1f11c47052a218e762daddbfb9e99f6568f80b5364b8588ce35440400e80a398ce8f99034d2292cc37c8ebd530feb583a05e954341f8a027b2a7d3a1f09bf854dc5d5d953aa396e4f38cab199e2d2e108abe156f82e30977fcb4d8ff942d75dbebed2e143953a93f6caad3d6111f44b7d4f820ff9c0069bb51ecded318c5c0000000049454e44ae426082</data>
        </image>
    </images>
    <connections>
        <connection>
            <sender>fileOpenAction</sender>
            <signal>activated()</signal>
            <receiver>Form1</receiver>
            <slot>OpenFile()</slot>
        </connection>
        <connection>
            <sender>fileSaveAction</sender>
            <signal>activated()</signal>
            <receiver>Form1</receiver>
            <slot>fileSave()</slot>
        </connection>
        <connection>
            <sender>fileSaveAsAction</sender>
            <signal>activated()</signal>
            <receiver>Form1</receiver>
            <slot>fileSaveAs()</slot>
        </connection>
        <connection>
            <sender>OK</sender>
            <signal>clicked()</signal>
            <receiver>Form1</receiver>
            <slot>getVal()</slot>
        </connection>
        <connection>
            <sender>fileOpenAction</sender>
            <signal>activated()</signal>
            <receiver>Form1</receiver>
            <slot>OpenFile()</slot>
        </connection>
        <connection>
            <sender>fileSaveAction</sender>
            <signal>activated()</signal>
            <receiver>Form1</receiver>
            <slot>SaveFile()</slot>
        </connection>
        <connection>
            <sender>fileSaveAsAction</sender>
            <signal>activated()</signal>
            <receiver>Form1</receiver>
            <slot>SaveFileAs()</slot>
        </connection>
    </connections>
    <slots>
        <slot>OpenFile()</slot>
        <slot>SaveFile()</slot>
        <slot>fileSave()</slot>
        <slot>fileSaveAs()</slot>
        <slot>filePrint()</slot>
        <slot>getVal()</slot>
        <slot>SaveFileAs()</slot>
    </slots>
    <layoutdefaults spacing="6" margin="11"/>
    </UI>
    

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include "window.h"
    #include "configfile.h"
    
    class mainwindow : public Form1
    {
      Q_OBJECT
    
    public:
      mainwindow(QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
      ~mainwindow();
      /*$PUBLIC_FUNCTIONS$*/
    
    public slots:
      /*$PUBLIC_SLOTS$*/
      virtual void          getVal();
      virtual void          OpenFile();
    
    protected:
      /*$PROTECTED_FUNCTIONS$*/
    
    protected slots:
      /*$PROTECTED_SLOTS$*/
    
    };
    
    #endif
    

    mainwindow.cpp

    #include "mainwindow.h"
    #include <qmainwindow.h>
    #include <qlabel.h>
    #include <qpushbutton.h>
    #include <qspinbox.h>
    #include <qlineedit.h>
    #include <qfiledialog.h>
    
    cConfigFile Configuration(CONFIG);
    
    mainwindow::mainwindow(QWidget* parent, const char* name, WFlags fl)
    : Form1(parent,name,fl)
    {
    }
    
    mainwindow::~mainwindow()
    {
    }
    
    void mainwindow::OpenFile()
    {
       QString FileName = QFileDialog::getOpenFileName(".","*.cfg",this);
       if (!FileName.isEmpty())
          Configuration.Load(FileName);
    }
    

    Das Configuration.Load(FileName); kann man ja zum Test mal durch eine Ausgabe
    von FileName auf der Konsole ersetzen. Sonst muss ich diese Klasse auch noch
    posten. Die ist ziemlich lang, und noch nicht ganz fertig. Das GUI ist auch
    nur ein Test für diese Klasse, deshalb sieht es so popelig aus.
    😃



  • Schau dir im designer die Connections an. Du hast das Open Signal und die anderen doppelt connected.



  • Du hast recht!
    Hab ich übersehen.
    Das erklärt einiges.
    Naja, kann passieren.
    Danke!


Anmelden zum Antworten