• 12321阅读
  • 12回复

程序编译出错 [复制链接]

上一主题 下一主题
离线catsoft
 

只看楼主 倒序阅读 楼主  发表于: 2006-04-16
这是我除hello外的第二个程序,怎么也改不正确,头急都晕了,求高手帮忙!! 
谢谢!!!!

程序:
#include <QApplication.h>
#include <QPushButton.h>
#include <QWidget.h>
#include <QFont.h>
#include <QLabel.h>

class mainwindow : public QWidget
{
  public:
      mainwindow();
  private:
      QPushButton *b1;
      QLabel *label;
    }

16 mainwindow::mainwindow()
17 {  
     setMinimumSize(500,500);
     setGeometry(200,200,500,500);
   b1 = new QPushButton("第一个按钮",this);
     b1->setGeometry(200,100,100,100);
     b1->setFont(QFont("TIMES",18,QFont::Bold));
 
    label = new QLabel(this);
    label->setText("这是第一行\n这是第二行");
26   label->setAlignment(Aligncenter);
27 }

void main(int argc, char **argv)
{
  QApplication app(argc, argv);
  mainwindow w;
  w.show();
  app.exec();
}

错误提示:
g++ -c -g -g -frtti -fexceptions -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL
-DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"E:/Qt/4.1.1/
include/QtCore" -I"E:/Qt/4.1.1/include/QtGui" -I"E:/Qt/4.1.1/include" -I"." -I"E
:/Qt/4.1.1/include/ActiveQt" -I"debug" -I"." -I"E:/Qt/4.1.1/mkspecs/win32-g++" -
o debug\test.o test.cpp

test.cpp:17: error: new types may not be defined in a return type
test.cpp:17: error: return type specification for constructor invalid
test.cpp: In constructor `mainwindow::mainwindow()':
test.cpp:26: error: `Aligncenter' undeclared (first use this function)
test.cpp:26: error: (Each undeclared identifier is reported only once for each f
unction it appears in.)
mingw32-make: *** [debug\test.o] Error 1


顺便问一下,怎么连行号一起导出啊??

谢谢了!!!!!!!!
[ 此贴被XChinux在2006-04-17 10:52重新编辑 ]
离线catsoft

只看该作者 1楼 发表于: 2006-04-17
求高手解答一下啊,我实在找不出问题在哪儿了. '旁观者清' 有时候别人很容易发现所在的啊!

谢了!!!!!!!!!!!!
离线XChinux

只看该作者 2楼 发表于: 2006-04-17
从编译器来自己查找错误,要学会。根本问题在于你程序代码的不严谨。

一、类定义完后,要在后面加分号";",你没有加。C++语法错误。
二、编译信息已经告诉你了,Aligncenter没有定义,这是你的错误,应该为Qt::AlignCenter
三、看你是在Windows下使用,所以你程序的头文件才没有提示错误,正确的应该为下面的样子的,注意大小写:
#include <QApplication>或者#include <qapplication.h>
在Linux下大小写不区分可是要报错的。
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线catsoft

只看该作者 3楼 发表于: 2006-04-17
谢谢版主啊!!多次得到你的帮助,实在感谢  可惜我是菜鸟不能帮助其他人解决问题!

还有:
我也用过Qt::AlignCenter 不过它说 QT也是未被定义的,最后我直接复制了你打的 Qt::AlignCenter
然后就没哪个错误了,我晕!!!

还有啊,刚才最后提示这个错误 

E:\Qt\程序\test1>qtd
g++ -c -g -g -frtti -fexceptions -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL
-DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"E:/Qt/4.1.1/
include/QtCore" -I"E:/Qt/4.1.1/include/QtGui" -I"E:/Qt/4.1.1/include" -I"." -I"E
:/Qt/4.1.1/include/ActiveQt" -I"debug" -I"." -I"E:/Qt/4.1.1/mkspecs/win32-g++" -
o debug\a.o a.cpp
a.cpp:17: error: stray '\161' in program
a.cpp:17: error: stray '\161' in program
a.cpp: In constructor `mainwindow::mainwindow()':
a.cpp:18: error: stray '\161' in program
a.cpp:18: error: stray '\161' in program
a.cpp:19: error: stray '\161' in program
a.cpp:19: error: stray '\161' in program
a.cpp:20: error: stray '\161' in program
a.cpp:20: error: stray '\161' in program
a.cpp:20: error: stray '\161' in program
a.cpp:20: error: stray '\161' in program
a.cpp:21: error: stray '\161' in program
a.cpp:21: error: stray '\161' in program
a.cpp:22: error: stray '\161' in program
a.cpp:22: error: stray '\161' in program
a.cpp:25: error: stray '\161' in program
a.cpp:25: error: stray '\161' in program
a.cpp:27: error: stray '\161' in program
a.cpp:27: error: stray '\161' in program
mingw32-make: *** [debug\a.o] Error 1

我实在没看懂这是什么错误(\161 什么意思啊), 后来实在没办法,我把16-27行 所有行前面用于排版的空格都去了,但是还是提示18-26行有'\16'这个错误,然后我又把18-26行前面又都加了一些空格,这时'\16'的错误才没了。现在我把18-26前面的空格再次都去掉后,它也没错误了!

我晕啦,虽然现在错误没有了,但我还是没明白这是什么错误, 我想不是空格的问题,而是我在前面操作过程中改了其它的东西。 

谁告诉我这是什么错误吗?不然下次遇到这个错误,我还得这么试啊!!!
离线billdates
只看该作者 4楼 发表于: 2006-04-19
Try use English instead of 这是第一行\n这是第二行 and 第一个按钮
离线billdates
只看该作者 5楼 发表于: 2006-04-19
Oops. Sorry. Your code block

"16 mainwindow::mainwindow()
17 {
   setMinimumSize(500,500);
   setGeometry(200,200,500,500);
   b1 = new QPushButton("第一个按钮",this);
   b1->setGeometry(200,100,100,100);
   b1->setFont(QFont("TIMES",18,QFont::Bold));

  label = new QLabel(this);
  label->setText("这是第一行\n这是第二行");
26   label->setAlignment(Aligncenter);
27 }
"
should be in a C++ file but it appears to be in the same .h file and after "private". Not trying to offend you: you probably should spend some time in pure C++ first before going to QT.
离线肥鸽子
只看该作者 6楼 发表于: 2009-06-02
谢谢二楼,我也是类定义了没有加分号,真是对自己无语了~~~~
离线foxyz

只看该作者 7楼 发表于: 2009-06-03
建议楼主先好好读C++入门的书籍。推荐c++ primer
离线rqzrqh

只看该作者 8楼 发表于: 2009-06-03
例子多比较,先拿简单的程序调试,QT没有C++基础也是可以学的,但是要想提高还是需要学C++
离线daizb05
只看该作者 9楼 发表于: 2009-06-04
引用第3楼catsoft于2006-04-17 13:17发表的  :
谢谢版主啊!!多次得到你的帮助,实在感谢 [表情]  可惜我是菜鸟不能帮助其他人解决问题!
还有:
我也用过Qt::AlignCenter 不过它说 QT也是未被定义的,最后我直接复制了你打的 Qt::AlignCenter
然后就没哪个错误了,我晕!!!
.......

复制就正确??你不会是输入法出问题了吧
离线qieziting
只看该作者 10楼 发表于: 2009-06-05
a.cpp:20: error: stray '\161' in program

这个明显是用了中文的标点,估计用的是中文输入法

写代码的时候请一定要用英文标点,lz……
离线yangyunzhao

只看该作者 11楼 发表于: 2009-06-11
引用第8楼rqzrqh于2009-06-03 18:03发表的  :
例子多比较,先拿简单的程序调试,QT没有C++基础也是可以学的,但是要想提高还是需要学C++

不太同意你的观点,没有C++基础寸步难行。没有很好的C++基础,不可能精通QT
离线qnbs1
只看该作者 12楼 发表于: 2010-02-03
如果代码中含有全角标点的话,就会这样。可能是全角的Tab
快速回复
限100 字节
 
上一个 下一个