• 8520阅读
  • 7回复

【提问】我是新手,请大家帮我看一下这是怎么回事 [复制链接]

上一主题 下一主题
离线xcgwy
 
只看楼主 倒序阅读 楼主  发表于: 2006-02-16
main.cpp:

#include <QApplication>
#include <QPushButton>
#include <QLabel>
#include <QHBoxLayout>
#include <QWidget>
class CMywin : public QWidget
  {
  Q_OBJECT
  public:
    CMywin(QWidget *parent=0);
    QLabel *label1;
    QPushButton *button1;
    QPushButton *button2;
  private slot:
    void button1click();
    void button2click();
  };
CMywin::CMywin(QWidget *parent)
  :QWidget(parent)
  {
  label1=new QLabel(tr("label1"));
  button1 = new QPushButton(tr("button1"));
  connect(button1, SIGNAL(clicked()), this, SLOT(button1click()));
  button2 = new QPushButton(tr("button2"));
  connect(button2, SIGNAL(clicked()), this, SLOT(button2click()));
  QHBoxLayout *buttonsLayout = new QHBoxLayout;
  buttonsLayout->addStretch();
  buttonsLayout->addWidget(label1);
  buttonsLayout->addWidget(button1);
  buttonsLayout->addWidget(button2);
  setLayout(buttonsLayout);
  }
void CMywin::button1click()
  {
  label1->setText("hello");
  }
void CMywin::button2click()
  {
 
  }
int main(int argc, char *argv[])
{
  QApplication app(argc, argv);

  CMywin mywin;

  mywin.show();
  return app.exec();
}

命令如下:
qmake -project 正常
qmake 正常
make
错误信息:
E:\test>make
make -f Makefile.Debug
make[1]: Entering directory `E:/test'
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"D:/Qt/QT4.1.
0/include/QtCore" -I"D:/Qt/QT4.1.0/include/QtGui" -I"D:/Qt/QT4.1.0/include" -I".
" -I"D:/Qt/QT4.1.0/include/ActiveQt" -I"debug" -I"." -I"D:/Qt/QT4.1.0/mkspecs/wi
n32-g++" -o debug\main.o main.cpp
main.cpp:43: error: expected `:' before "slot"
main.cpp:44: error: expected primary-expression before "void"
main.cpp:44: error: ISO C++ forbids declaration of `slot' with no type
main.cpp:44: error: expected `;' before "void"
main.cpp:63: error: no `void CMywin::button1click()' member function declared in
class `CMywin'
main.cpp:77: error: no `void CMywin::button2click()' member function declared in
class `CMywin'
main.cpp:77: error: `void CMywin::button2click()' and `void CMywin::button2click
()' cannot be overloaded
make[1]: *** [debug\main.o] Error 1
make[1]: Leaving directory `E:/test'
make: *** [debug] Error 2

我是新手,这是怎么回事啊。先谢过了。
[ 此贴被fanyu在2006-02-16 12:09重新编辑 ]
离线xuxinshao

只看该作者 1楼 发表于: 2006-02-16
缺少moc文件
离线xcgwy
只看该作者 2楼 发表于: 2006-02-16
下面是引用xuxinshao于2006-02-16 10:15发表的:
缺少moc文件

先谢过。
在QT安装目录下bin时有moc.exe啊
那现在该怎么办呢?
离线fanyu
只看该作者 3楼 发表于: 2006-02-16
你用发行版来编译试试看,qt 4 for MingW,系统默认是没有qt的调试库的,只有发行库。
即make -f Makefile.release来编译。

还有就是类定义和实现要分开,即分别写在.h和cpp文件里,写在一个文件里是不行的。
离线xcgwy
只看该作者 4楼 发表于: 2006-02-16
下面是引用fanyu于2006-02-16 12:05发表的:
你用发行版来编译试试看,qt 4 for MingW,系统默认是没有qt的调试库的,只有发行库。
即make -f Makefile.release来编译。
还有就是类定义和实现要分开,即分别写在.h和cpp文件里,写在一个文件里是不行的。

还是不行,不过我编译中的tutorial中的t7是能编译过的。
我用的是QT4.1.0。
离线renstone

只看该作者 5楼 发表于: 2006-02-17
private slot:

private slots:
??

这种问题属于语法错误。是在编译期发生的,一般遇到这种问题,应当仔细检查语法。
离线cavendish

只看该作者 6楼 发表于: 2006-02-18
private slots
这个有点意思
离线xcgwy
只看该作者 7楼 发表于: 2006-02-20
我已经解决,当然了,这不是什么private slots:语法问题。
快速回复
限100 字节
 
上一个 下一个