iso C++ forbids declaration of ""with no type 是什么原因 怒了

40岁的码农也有春天 2011-05-13 11:37:58
#include <QtGui/QApplication>
#include "mainwindow.h"
#include <qwidget.h>
#include <qpushbutton.h>
#include <qfont.h>
#include <qlineedit.h>
#include <qstring.h>
class MyMainWindow : public QWidget
{
Q_OBJECT
public:
MyMainWindow();
public slots:
void CopyEdit(int);
private:
QPushButton *b1;
QPushButton *b2;
QPushButton *b3;
QLineEdit *ledit;
signals:
void valueChanged(int);
};
MyMainWindow::CopyEdit(int)
{
ledit->setText("this is a line of text!");
emit valueChanged(int);
connect(b2,SIGNAL(clicked()),ledit,SLOT(valueChanged(int)));
};
MyMainWindow::MyMainWindow()
{
this->setGeometry(300,300,400,400);
b1=new QPushButton("Click here to mark the tsxt",this);
b1->setGeometry(0,0,400,20);
b1->setFont(QFont("Times",10,QFont::Bold));
b2=new QPushButton("click here to unmark the text",this);
b2->setGeometry(0,25,400,20);
b2->setFont(QFont("Times",10,QFont::Bold));
b3=new QPushButton("click here to remove the text",this);
b3->setGeometry(0,50,400,20);
b3->setFont(QFont("Times",10,QFont::Bold));
ledit=new QLineEdit("this is a line of text!",this);
ledit->setGeometry(0,80,400,40);
connect(b1,SIGNAL(clicked()),ledit,SLOT(selectAll()));
//connect(b2,SIGNAL(clicked()),ledit,SLOT(CopyEdit()));
connect(b3,SIGNAL(clicked()),ledit,SLOT(clear()));

};

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyMainWindow w;
w.show();

return a.exec();
}
...全文
5011 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
袁保康 2012-08-23
  • 打赏
  • 举报
回复 1
[Quote=引用 7 楼 的回复:]

遇到了同样的问题,指定返回值之后,就没有事儿了
[/Quote]
帮我解决了问题,谢谢;另加一句:就算没有返回值也要用个void
icive 2011-08-23
  • 打赏
  • 举报
回复
遇到了同样的问题,指定返回值之后,就没有事儿了
zhangfl20 2011-06-28
  • 打赏
  • 举报
回复
也遇到同样的问题了
gemfield 2011-05-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 tingzhongxiang 的回复:]

提示如下:
iso C++ forbids declaration of "CopyEdit"with no type QT
prototype for "int MyMainWindow::CopyEdit(int)"dose not match any class"MyMainWindow"
cabdidate is "void MyMainWindow::CopyEdit(int)"……
[/Quote]
ISO/IEC 14882:1998 7.1.5第2小节有所描述
法尔我给他 2011-05-16
  • 打赏
  • 举报
回复
没指定返回值.
dbzhang800 2011-05-13
  • 打赏
  • 举报
回复
[Quote=引用楼主 tingzhongxiang 的回复:]
void MyMainWindow::CopyEdit(int)
{
ledit->setText("this is a line of text!");
emit valueChanged(int);
connect(b2,SIGNAL(clicked()),ledit,SLOT(valueChanged(int)));
};
[/Quote]
没什么好怒的,你自己没指定返回值。按照C的传统,默认就是int了。
donaldking 2011-05-13
  • 打赏
  • 举报
回复
好像是说父类里面(QWidget?)是int CopyEdit(int)而子类里面(MyMainWindow)是void CopyEdit(int),这个两个函数不匹配,把MyMainWindow里面改成int CopyEdit(int)应该就好了。
  • 打赏
  • 举报
回复
提示如下:
iso C++ forbids declaration of "CopyEdit"with no type QT
prototype for "int MyMainWindow::CopyEdit(int)"dose not match any class"MyMainWindow"
cabdidate is "void MyMainWindow::CopyEdit(int)"

16,802

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧