开发者

File not found during compilation

开发者 https://www.devze.com 2023-03-24 02:53 出处:网络
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 inh

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

精彩评论

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

关注公众号