各位 我在编译《Foundations_of_Qt_Development》书中第四章的mdi程序中
下述函数发生错误:
void MdiWindow::fileNew()
{
DocumentWindow *document = new DocumentWindow();//该语句出错
workspace->addWindow( document );
connect( document, SIGNAL(copyAvailable(bool)), ui.actionCut, SLOT(setEnabled(bool)) );
connect( document, SIGNAL(copyAvailable(bool)), ui.actionCopy, SLOT(setEnabled(bool)) );
document->show();
}
错误信息如下:
mingw32-make debug
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `E:/KZHM8/workspace/mdi'
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\mdi.exe debug/main.o debug/mdiwindow.o debug/moc_mdiwindow.o -L"f:\Qt\4.4.3\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
debug/mdiwindow.o: In function `ZN9MdiWindow7fileNewEv':
E:/KZHM8/workspace/mdi/mdiwindow.cpp:74: undefined reference to `DocumentWindow::DocumentWindow(QWidget*)'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\mdi.exe] Error 1
mingw32-make[1]: Leaving directory `E:/KZHM8/workspace/mdi'
mingw32-make: *** [debug] Error 2
我的父窗口实用Qt Eclipse Integration v1.4.1生成的,子窗体直接拷贝书中的代码。
恳请各位高手帮帮忙 谢谢
==================================mdiwindow.h================================
#ifndef MDIWINDOW_H
#define MDIWINDOW_H
#include <QtGui/QMainWindow>
#include "ui_mdiwindow.h"
class QAction;
class QWorkspace;
class QSignalMapper;
class QMenu;
class DocumentWindow;
class MdiWindow : public QMainWindow
{
Q_OBJECT
public:
MdiWindow(QWidget *parent = 0);
~MdiWindow();
private:
Ui::MdiWindowClass ui;
DocumentWindow *activeDocument();
QWorkspace *workspace;
QSignalMapper *mapper;
protected:
void closeEvent( QCloseEvent *event );
private slots:
void fileNew();
/*
void editCut();
void editCopy();
void editPaste();
void helpAbout();*/
void enableActions();
// void updateWindowList();
};
#endif // MDIWINDOW_H
============================mdiwindow.cpp=======================================
#include <QCloseEvent>
#include <QMessageBox>
#include <QWorkspace>
#include <QSignalMapper>
#include "mdiwindow.h"
#include "documentwindow.h"
class DocumentWindow;
//DocumentWindow::DocumentWindow();
MdiWindow::MdiWindow(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
MdiWindow::~MdiWindow()
{
setWindowTitle( tr( "MDI" ) );
workspace = new QWorkspace;
setCentralWidget( workspace );
connect( workspace, SIGNAL(windowActivated(QWidget *)), this, SLOT(enableActions()));
mapper = new QSignalMapper( this );
connect( mapper, SIGNAL(mapped(QWidget*)), workspace, SLOT(setActiveWindow(QWidget*)) );
connect(ui.actionNew, SIGNAL(triggered()), this, SLOT(fileNew()) );
/* createActions();
createMenus();
createToolbars();
statusBar()->showMessage( tr("Done") );*/
enableActions();
}
void MdiWindow::closeEvent( QCloseEvent *event )
{
workspace->closeAllWindows();
if( !activeDocument() )
event->accept();
else
event->ignore();
}
DocumentWindow *MdiWindow::activeDocument()
{
return (DocumentWindow*)(workspace->activeWindow());
}
void MdiWindow::enableActions()
{
bool hasDocuments = (activeDocument() != 0 );
ui.actionClose->setEnabled( hasDocuments );
ui.actionPaste->setEnabled( hasDocuments );
ui.actionTile->setEnabled( hasDocuments );
ui.actionCascade->setEnabled( hasDocuments );
ui.actionNext->setEnabled( hasDocuments );
ui.actionPrevious->setEnabled( hasDocuments );
//separatorAction->setVisible( hasDocuments );
bool hasSelection = hasDocuments && activeDocument()->textCursor().hasSelection();
ui.actionCut->setEnabled( hasSelection );
ui.actionCopy->setEnabled( hasSelection );
}
void MdiWindow::fileNew()
{
DocumentWindow *document ;
document = new DocumentWindow();
workspace->addWindow( document );
connect( document, SIGNAL(copyAvailable(bool)), ui.actionCut, SLOT(setEnabled(bool)) );
connect( document, SIGNAL(copyAvailable(bool)), ui.actionCopy, SLOT(setEnabled(bool)) );
document->show();
}