QT slots



  • hi,
    kann mir hier einer ein leichtes Beispiel für Qt (slots und singnals)sagen oder scheiben ???

    ich kappier des nämlich kein bissle!! und wenn's ich mal mach dann gets ned!

    danke



  • schau dir mal das Qt Tutorial an http://www.trolltech.com/developer/index.html



  • ja hatte ich schon wenn ich die Beispiele mach kommt immer ein Fehler!

    ich check des einfach ned!!



  • Was für nen Fehler kommt denn?? Mit solchen ungenauen Angaben kann man nix anfangen...



  • Mein Code:

    #include <qapplication.h>
    #include <qpushbutton.h>
    #include <qfont.h>
    #include <qmessagebox.h>
    
    class MyWidget : public QWidget
    {
        Q_OBJECT
    public slots:
        void my_slot();
    public:
        MyWidget( QWidget *parent=0, const char *name=0 );
    
    };
    void MyWidget::my_slot()
    {
     QMessageBox::about(this, "About Word2HTML","Hello World");
    }
    
    MyWidget::MyWidget( QWidget *parent, const char *name )
            : QWidget( parent, name )
    {
        setMinimumSize( 200, 120 );
        setMaximumSize( 200, 120 );
    
        QPushButton *quit = new QPushButton(this);
    
        quit->setGeometry(10,10,80,25);
        quit->setText("Button");
    
        connect(quit, SIGNAL(clicked()), this, SLOT(my_slot()) );
    }
    
    int main( int argc, char **argv )
    {
        QApplication a( argc, argv );
    
        MyWidget w;
        w.setGeometry( 100, 100, 200, 120 );
        a.setMainWidget( &w );
        w.show();
        return a.exec();
    }
    

    Mein fehler:
    main.o: In function MyWidget::MyWidget[not-in-charge](QWidget*, char const*)': /home/matze/devolpment/lml/lml/main.cpp:23: undefined reference tovtable for MyWidget'
    /home/matze/devolpment/lml/lml/main.cpp:23: undefined reference to vtable for MyWidget' main.o: In functionMyWidget::MyWidget[in-charge](QWidget*, char const*)':
    /home/matze/devolpment/lml/lml/main.cpp:23: undefined reference to vtable for MyWidget' /home/matze/devolpment/lml/lml/main.cpp:23: undefined reference tovtable for MyWidget'
    main.o: In function MyWidget::~MyWidget [in-charge]()': /home/matze/devolpment/lml/lml/main.cpp:17: undefined reference tovtable for MyWidget'
    main.o:/home/matze/devolpment/lml/lml/main.cpp:17: more undefined references to `vtable for MyWidget' follow
    collect2: ld returned 1 exit status

    ich habe kein anung was daran Falsch sein kann!! ihr??



  • Also du musst die Deklaration und Implementierung trennen. Ich hatte den gleichen Fehler, aber jetzt läufts, wenn ich folgende Dateien habe:

    test.h:

    #ifndef TEST_H
    #define TEST_H
    
    #include <qfont.h>
    #include <qmessagebox.h>
    
    class MyWidget : public QWidget
    {
        Q_OBJECT
    public slots:
        void my_slot();
    public:
        MyWidget( QWidget *parent=0, const char *name=0 );
    
    };
    #endif
    

    test.cpp

    #include <qapplication.h>
    #include <qpushbutton.h>
    #include <qfont.h>
    #include <qmessagebox.h>
    
    #include "test.h"
    
    void MyWidget::my_slot()
    {
     QMessageBox::about(this, "About Word2HTML","Hello World");
    }
    
    MyWidget::MyWidget( QWidget *parent, const char *name )
            : QWidget( parent, name )
    {
        setMinimumSize( 200, 120 );
        setMaximumSize( 200, 120 );
    
        QPushButton *quit = new QPushButton(this);
    
        quit->setGeometry(10,10,80,25);
        quit->setText("Button");
    
        connect(quit, SIGNAL(clicked()), this, SLOT(my_slot()) );
    }
    

    main.cpp:

    #include <qapplication.h>
    #include <qpushbutton.h>
    #include <qfont.h>
    #include <qmessagebox.h>
    
    #include "test.h"
    
    int main( int argc, char **argv )
    {
        QApplication a( argc, argv );
    
        MyWidget w;
        w.setGeometry( 100, 100, 200, 120 );
        a.setMainWidget( &w );
        w.show();
        return a.exec();
    }
    

    qmake -project
    qmake
    make

    So funktionierts bei mir....sonst fehlen wohl die moc Dateien, die von diesem Meta Compiler erstellt werden. Jetzt sind sie jedenfalls da. 😃

    [EDIT]
    Vorausgesetzt natürlich, du erstellst dein Makefile nicht manuell. Sonst musste dir das mal zu Gemüte führen:
    http://doc.trolltech.com/3.1/moc.html
    [/EDIT]



  • Danke Danke jetzt check ich das!!


Anmelden zum Antworten