开发者

File not found during compilation

What is wrong with the code bellow? When I compile it I get a warning that file not found. Something is invalid. I'm probably making a few mistakes here. I think the problem is perhaps with the way I inherit from QWidget.

   #include <QtGui/QApplication>
    #include "filedialogs.h"

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);

        FileDialogs w;
        w.openFile();

        return 0;
    }

#ifndef FILEDIALOGS_H
#define FILEDIALOGS_H

    #include <QWidget>
    class QFileDialog;

    class FileDialogs : public QWidget
    {

    public:
        FileDialogs(QWidget *parent = 0);
        ~FileDialogs();

        void openFile();
    };

    #endif // FILEDIALOGS_H

#include <QFileDialog>
#include "filedialogs.h"

FileDialogs::FileDialogs(QWidget *parent)
    : QWidget(parent)
{
}

FileDialogs::~FileDialogs()
{

}

void FileDialogs::openFile()
{
  QString filename = QFileDialog::getOpenFileName(
      this,
      tr("Open Document"),
      QDir::currentPath(),
      tr("Document files (*.doc *.rtf);;All files 开发者_如何学JAVA(*.*)") );

  if( !filename.isNull() )
  {
    qDebug( filename.toAscii() );
  }
}

#-------------------------------------------------
#
# Project created by QtCreator 2011-07-29T19:06:33
#
#-------------------------------------------------

QT       += core gui

TARGET = exX
TEMPLATE = app


SOURCES += main.cpp\
        filedialogs.cpp

HEADERS  += filedialogs.h


This error message is emitted by the MOC compiler. You are missing the Q_OBJECT macro. Put it in your class declaration like this:

class FileDialogs : public QWidget
{
    Q_OBJECT

    public:
    ....


I know this Question is very old. But in my case it was another problem. I had to include the path of the headers manually in the .pro file.

INCLUDEPATH += src/subdir
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜