当前位置: 代码迷 >> QT开发 >> 出错求解,该如何解决
  详细解决方案

出错求解,该如何解决

热度:29   发布时间:2016-04-25 04:49:32.0
出错求解
错误信息error: new types may not be defined in a return type

源代码.h文件

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include<QThread>

namespace Ui {
  class MainWindow;
}

class MainWindow : public QMainWindow
{
  Q_OBJECT

public:
  explicit MainWindow(QWidget *parent = 0);
  ~MainWindow();

private:
  Ui::MainWindow *ui;
};

class MyThread:public QThread
{
public:
  virtual void run();
}
#endif // MAINWINDOW_H


.cPP 文件
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QThread>

MainWindow::MainWindow(QWidget *parent) :
  QMainWindow(parent),
  ui(new Ui::MainWindow)
{
  ui->setupUi(this);
  MyThread a;
  MyThread b;
  a.start();
  b.start();
  a.wait();
  b.wait();

}

MainWindow::~MainWindow()
{
  delete ui;
}

void MyThread::run()
{
  for(int count=0;count<20;count++)
  {
  sleep(1);
  qDeug("ping!");

  }
}




------解决方案--------------------
class MyThread:public QThread
{
public:
virtual void run();
}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!;


少了个分号
------解决方案--------------------
.h最后分号结尾
这种编辑错误IDE就会提示你的,LZ不用Qt-creator吗
  相关解决方案