Seite 1 von 1

Signals und Slots connecten

Verfasst: 6. Mai 2006 14:07
von Schwarzherz
Ich versuche gerade bei einem unter Qt4 programmierten Text Editor die undo() Funktionen zu implementieren.

Der connect für die action lautet:

Code: Alles auswählen

QObject::connect(actionUndo, SIGNAL(triggered()), this, SLOT(undo()));

Die implementierte undo()-Funktion sieht so aus:

Code: Alles auswählen

public slots:
    void undo()
    {
        QTextDocument *codeTextDocument = codeTextEdit->document();
        codeTextDocument->undo();
    }

codeTextEdit ist wie eigentlich sowieso ersichtliche in QTextEdit Objekt.

Das Problem dabei liegt im connect, was mir folgende Compiler-Fehler beschert:

Code: Alles auswählen

g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o main.o main.cpp
Mainwindow.h: In member function ‘void Ui_MainWindow::connectSignalsSlots()’:
Mainwindow.h:272: error: no matching function for call to ‘QObject::connect(QAction*&, const char [13], Ui_MainWindow* const, const char [8])’
/usr/include/qt4/QtCore/qobject.h:174: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
/usr/include/qt4/QtCore/qobject.h:274: note:                 bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
make: *** [main.o] Fehler 1
Hat jemand ne Ahnung woran das liegen könnte?

Was ich so aus dieser Meldung schließen kann ist, dass der Typ von "this" nicht passt, aber keine Ahnung was da sonst hingehören könnte.

Re: Signals und Slots connecten

Verfasst: 6. Mai 2006 21:30
von patrik08
Schwarzherz hat geschrieben:

Code: Alles auswählen

public slots:
    void undo()
    {
        QTextDocument *codeTextDocument = codeTextEdit->document();
        codeTextDocument->undo();
    }
.
ist das eine header & source datei .. alles in einem?

header hat die deklaration...
filename*****.h

private slots:
void fileNew();
void fileOpen();
bool fileSave();
bool fileSaveAs();
void filePrint();
void filePrintPdf();


und source die funktionen...
filename*****.cpp
void ClasseName::fileNew()
{

}

ein undo beispiel ist auch im source von
qt4\demos\textedit zu finden..
mit funktionierenden code lern mann auch die policy der datei structur...