eigene Slots erstellen funktioniert nicht (Qt4.0)



  • Gute tag alle miteinander.. ich bin wirklich am verzweifeln .. und zwar will ich mir grade in Qt ein bischen einarbeiten und komm bei dem erstellen von Slots nicht wirklich weiter.. Mein problem ist das sich zwar mein Programm compelieren lässt aber bei drücken auf den Connectbutton wird es sofort geschlossen..

    ach ja und nicht wundern das sind später nicht alle funktionen meines programms.
    dient nur dazu um zu schauen ob ich mit dem connect button einen Com schnittstelle öffnen kann..

    Vielleicht noch zur anmerktung also die Port_Interface.h und zugehörige cpp funktioniern auf jeden fall das hab ich in einer Konsolenanwendung schon getestet..

    Meine Main:

    #include <qapplication.h>
    #include <qpushbutton.h>
    #include <QObject.h>
    #include "moc_Port_Connect.h"
    
    int main(int argc, char **argv)
    {
    
        QApplication app(argc,argv);
        QWidget *widget = new QWidget();
        widget->setGeometry(500,300,200,150);
    
        QPushButton *button = new QPushButton("Connect",widget);
        button->setGeometry(40,40,60,30);
    
        Port_Connect *con = new Port_Connect(widget);
        QObject::connect(button,SIGNAL(clicked()),con,SLOT(p_connect(void)));
    
        QObject::connect(button,SIGNAL(clicked()),con,SLOT(p_connect()));
    
        app.setActiveWindow(widget);
        app.setStyle("plastique");
        widget->show();
        return app.exec();
    

    Die Headerdatei Port_Connect.h:

    #ifndef PORT_CONNECT_H
    #define PORT_CONNECT
    
    #include <QObject.h>
    #include "Port_Interface.h"
    
    class Port_Connect: public QObject, public Port_Interface
        {
    
        Q_OBJECT
    
        public:
        Port_Connect(QWidget *parent) : QObject(parent){dwSetMask = EV_RXCHAR | EV_ERR;}
    
        public slots:
        void p_connect(void)
        {
        pi_open("COM2");
        }
    
        };
    #endif
    

    Die Headerdatei nach dem ich moc ausgeführt hab:

    /****************************************************************************
    ** Meta object code from reading C++ file 'Port_Connect.h'
    **
    ** Created: Di 25. Jul 17:05:06 2006
    **      by: The Qt Meta Object Compiler version 58 (Qt 4.0.0)
    **
    ** WARNING! All changes made in this file will be lost!
    *****************************************************************************/
    
    #include "Port_Connect.h"
    #if !defined(Q_MOC_OUTPUT_REVISION)
    #error "The header file 'Port_Connect.h' doesn't include <QObject>."
    #elif Q_MOC_OUTPUT_REVISION != 58
    #error "This file was generated using the moc from 4.0.0. It"
    #error "cannot be used with the include files from this version of Qt."
    #error "(The moc has changed too much.)"
    #endif
    
    static const uint qt_meta_data_Port_Connect[] = {
    
     // content:
           1,       // revision
           0,       // classname
           0,    0, // classinfo
           1,   10, // methods
           0,    0, // properties
           0,    0, // enums/sets
    
     // slots: signature, parameters, type, tag, flags
          14,   13,   13,   13, 0x0a,
    
           0        // eod
    };
    
    static const char qt_meta_stringdata_Port_Connect[] = {
        "Port_Connect\0\0p_connect()\0"
    };
    
    const QMetaObject Port_Connect::staticMetaObject = {
        { &QObject::staticMetaObject, qt_meta_stringdata_Port_Connect,
          qt_meta_data_Port_Connect, 0 }
    };
    
    const QMetaObject *Port_Connect::metaObject() const
    {
        return &staticMetaObject;
    }
    
    void *Port_Connect::qt_metacast(const char *_clname)
    {
        if (!_clname) return 0;
        if (!strcmp(_clname, qt_meta_stringdata_Port_Connect))
    	return static_cast<void*>(const_cast<Port_Connect*>(this));
        if (!strcmp(_clname, "Port_Interface"))
    	return static_cast<Port_Interface*>(const_cast<Port_Connect*>(this));
        return QObject::qt_metacast(_clname);
    }
    
    int Port_Connect::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
    {
        _id = QObject::qt_metacall(_c, _id, _a);
        if (_id < 0)
            return _id;
        if (_c == QMetaObject::InvokeMetaMethod) {
            switch (_id) {
            case 0: p_connect(); break;
            }
            _id -= 1;
        }
        return _id;
    }
    

    vielleicht könnt ihr mir ja dabei helfen.. wäre echt nett hock hier nämlich schon seit guten 9 Stunden hab im Internet gesucht und gelesen und die komplette Trolltech documentation auswendig gelernt 😉 aber komm nicht wirklich weiter

    zu guter letzt sollte ich vielleicht sagen das ich CodeBlocks als Entwicklungsplatform benutze..

    gruß Dominik



  • Ich weiss nicht was du falsch machst, aber das folgende Programm, was deinem sehr ähnlich ist, gibt beim druck auf die Taste den Text aus:

    #include <QApplication> 
    #include <QPushButton> 
    #include <QObject> 
    
    #include "port_connect.h"
    
     int main(int argc, char **argv) 
     { 
    
         QApplication app(argc,argv); 
         QWidget *widget = new QWidget(); 
         widget->setGeometry(500,300,200,150); 
    
         QPushButton *button = new QPushButton("Connect",widget); 
         button->setGeometry(40,40,60,30); 
    
         Port_Connect *con = new Port_Connect(widget); 
         QObject::connect(button,SIGNAL(clicked()),con,SLOT(p_connect(void))); 
    
         QObject::connect(button,SIGNAL(clicked()),con,SLOT(p_connect())); 
    
         app.setActiveWindow(widget); 
         app.setStyle("plastique"); 
         widget->show(); 
         return app.exec();
    }
    
    #ifndef PORT_CONNECT_H 
    #define PORT_CONNECT 
    
    #include <iostream>
    
    #include <QObject> 
    
    class Port_Connect: public QObject
    { 
    
       Q_OBJECT 
    
       public: 
       Port_Connect(QWidget * parent)
       {
       } 
    
       public slots: 
       void p_connect(void) 
       { 
          std::cout << "Taste gedrückt." << std::endl;
       } 
    
    }; 
    #endif
    

    Ich habe es bei mir so übersetzt (Linux):

    qmake -project
    qmake
    make
    ./trot



  • danke schön ich werds mir mal anschauen..sollte noch jemand anderst eine idee oder material haben was mir weiter hilft immer her damit 😃



  • ich habe mir das proggie nicht genau angeschaut! aber 2 sachen sind wichtig: für das programm über die konsole aus um zu schauen welche connects warum nicht funzen, das würde dir echt helfen... qt spuckt darüber zur laufzeit fehler aus!

    dann
    QObject::connect(button,SIGNAL(clicked()),con,SLOT(p_connect(void)));

    mmh das void ist sinnlos, und schlechter stil! lass es weg, evtl klappts dann mit dem connect^^ ich glaubs zwar nicht aber du brauchst es ja net.


Anmelden zum Antworten