本人新手,刚写好一个很简单的程序,没有办法通过编译,我自己是在是找不出错误,麻烦过路高手帮忙指点下!
在Qdevelop中画好.ui,然后写代码如下:
.h文件
#ifndef MAINWINDOWIMPL_H
#define MAINWINDOWIMPL_H
//
#include <QMainWindow>
#include "ui_mainwindow.h"
//
class MainWindowImpl : public QMainWindow, public Ui::MainWindow
{
Q_OBJECT
public:
MainWindowImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
private slots:
void Sum();
};
#endif
.cpp文件
#include "mainwindowimpl.h"
//
MainWindowImpl::MainWindowImpl( QWidget * parent, Qt::WFlags f)
: QMainWindow(parent, f)
{
setupUi(this);
connect (pushButton, SIGNAL (clicked ()), lineEdit3, SLOT (Sum()));
}
void mainwindowimpl::Sum()
{
QString stemp;
long int ltemp;
ltemp=lineEdit1->text()->toLong()+lineEdit2->text().toLong();
stemp=QString::number(ltemp);
lineEdit3.setText(stemp);
}
main.cpp
#include <QApplication>
#include "mainwindowimpl.h"
//
int main(int argc, char ** argv)
{
QApplication app( argc, argv );
MainWindowImpl win;
win.show();
app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
return app.exec();
}
编译错误结果显示:
构建 (make)...
/usr/local/Trolltech/Qt-4.3.0/bin/uic ui/mainwindow.ui -o build/ui_mainwindow.h
g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.3.0/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.3.0/include/QtCore -I/usr/local/Trolltech/Qt-4.3.0/include/QtCore -I/usr/local/Trolltech/Qt-4.3.0/include/QtGui -I/usr/local/Trolltech/Qt-4.3.0/include/QtGui -I/usr/local/Trolltech/Qt-4.3.0/include -Ibuild -Ibuild -o build/mainwindowimpl.o src/mainwindowimpl.cpp
src/mainwindowimpl.cpp:9: syntax error before `::' token
src/mainwindowimpl.cpp:13: ISO C++ forbids declaration of `ltemp' with no type
src/mainwindowimpl.cpp:13: conflicting types for `int ltemp'
src/mainwindowimpl.cpp:12: previous declaration as `long int ltemp'
src/mainwindowimpl.cpp:13: `lineEdit1' was not declared in this scope
src/mainwindowimpl.cpp:13: `lineEdit2' was not declared in this scope
src/mainwindowimpl.cpp:14: ISO C++ forbids declaration of `stemp' with no type
src/mainwindowimpl.cpp:14: cannot convert `QString' to `int' in initialization
src/mainwindowimpl.cpp:15: syntax error before `.' token
make:
*** [build/mainwindowimpl.o] Error 1