Loss of include files
-
I'm still new to Qt Creator although I will claim some progress.
I am trying to add sound to my project which is a CW trainer for the Farnsworth method.To this end, I have added a header and source file and I have written a little code. My problem is that when I add the "#include" for the header file in the source file, the combination will not compile and some of the "#include" libraries are lost. That is, the message "no such file or directory" is issued.
I have tried to add the appropriate #includde moc_???.cpp but this doesn't seem to fix the problem. An attempt is made to produce the relevent cpp file but it is empty.The little bits of code follow
Sound.h...
#ifndef SOUND_H
#define SOUND_H
//#include <QAudioSink>
#include <QByteArray>
#include <QIODevice>
#include <QMediaDevices>
#include <QObject>
#include <QTimer>
#include <QAudioDevice>
class Sound : public QIODevice
{
Q_OBJECTprivate:
QMediaDevices *AllMediaDevices = nullpointer;
QAudioDevice DefaultAudioOutputDevice;public:
Sound();#endif // SOUND_H
and the source file, Sound.cpp contents...
#include "Sound.h"
//#include <QAudioDevice>
//#include <QAudioSink>
#include <QDebug>
#include <QtEndian>
#include <QtMath>
Sound::Sound(){
AllMediaDevices = new QMediaDevices(this);
DefaultAudioOutputDevice = AllMediaDevices->defaultAudioOutput();
}
#include "moc_Sound.cpp"Would some kind person tell me where I'm going wrong.
-
Hi,
Which errors are you getting exactly ?
Did you add these files to yourCMakeLists.txt
or.pro
file ? -
I'm still new to Qt Creator although I will claim some progress.
I am trying to add sound to my project which is a CW trainer for the Farnsworth method.To this end, I have added a header and source file and I have written a little code. My problem is that when I add the "#include" for the header file in the source file, the combination will not compile and some of the "#include" libraries are lost. That is, the message "no such file or directory" is issued.
I have tried to add the appropriate #includde moc_???.cpp but this doesn't seem to fix the problem. An attempt is made to produce the relevent cpp file but it is empty.The little bits of code follow
Sound.h...
#ifndef SOUND_H
#define SOUND_H
//#include <QAudioSink>
#include <QByteArray>
#include <QIODevice>
#include <QMediaDevices>
#include <QObject>
#include <QTimer>
#include <QAudioDevice>
class Sound : public QIODevice
{
Q_OBJECTprivate:
QMediaDevices *AllMediaDevices = nullpointer;
QAudioDevice DefaultAudioOutputDevice;public:
Sound();#endif // SOUND_H
and the source file, Sound.cpp contents...
#include "Sound.h"
//#include <QAudioDevice>
//#include <QAudioSink>
#include <QDebug>
#include <QtEndian>
#include <QtMath>
Sound::Sound(){
AllMediaDevices = new QMediaDevices(this);
DefaultAudioOutputDevice = AllMediaDevices->defaultAudioOutput();
}
#include "moc_Sound.cpp"Would some kind person tell me where I'm going wrong.
As @SGaist mentioned above, it seems like you've created the files manually in your filesystem without adding them to your project.
Check your project configuration and make sure all sources are listed in either yourYourProject.pro
or yourCMakeLists.txt
file.
Usually you don't need to include moc files by hand unless you have a headerless (e.g.main.cpp
only) program and you declare/defineQObject
classes in your source files. -
As @SGaist mentioned above, it seems like you've created the files manually in your filesystem without adding them to your project.
Check your project configuration and make sure all sources are listed in either yourYourProject.pro
or yourCMakeLists.txt
file.
Usually you don't need to include moc files by hand unless you have a headerless (e.g.main.cpp
only) program and you declare/defineQObject
classes in your source files.@Pl45m4
Thank you so much for replying.Yes, the files have been added to the project in my cwtrainer.pro.
In following your advice, I noticed that my QT "Setting" in my cwtrainer.pro file is
QT += core gui
which seems correct since I have largely completed the GUI for cwtrainer.
I have noticed in a couple of examples which I have looked at concerning producing the sound and which I can compile and run, the setting of the QT entry is
QT += multimedia widgets
These examples also have rudimentary GUIs so I have tried to add a multimedia widgets entry. I've tried just adding the above line to give,
QT += core gui
QT += multimedia widgets
This gives rise to a huge number of problems.
I've also tried replacing the QT += core gui by the line QT += multimedia widgets. This gives me a whole list of issues also.
Is there a way of changing the setting of the QT entry to accommodate both the core gui and multimedia widgets settings since it seems that such a solution will resolve my problemI've looked in the documentation but I cant seem to find an answer.
Thanks in advance. -
@Pl45m4
Thank you so much for replying.Yes, the files have been added to the project in my cwtrainer.pro.
In following your advice, I noticed that my QT "Setting" in my cwtrainer.pro file is
QT += core gui
which seems correct since I have largely completed the GUI for cwtrainer.
I have noticed in a couple of examples which I have looked at concerning producing the sound and which I can compile and run, the setting of the QT entry is
QT += multimedia widgets
These examples also have rudimentary GUIs so I have tried to add a multimedia widgets entry. I've tried just adding the above line to give,
QT += core gui
QT += multimedia widgets
This gives rise to a huge number of problems.
I've also tried replacing the QT += core gui by the line QT += multimedia widgets. This gives me a whole list of issues also.
Is there a way of changing the setting of the QT entry to accommodate both the core gui and multimedia widgets settings since it seems that such a solution will resolve my problemI've looked in the documentation but I cant seem to find an answer.
Thanks in advance.@Mark-K-R-Walker said in Loss of include files:
Is there a way of changing the setting of the QT entry to accommodate both the core gui and multimedia widgets settings since it seems that such a solution will resolve my problem
It concatenates.
So it'sQT += core gui widgets multimedia
-
If your header really looks like you showed us, it's no wonder you get compile errors:
#ifndef SOUND_H #define SOUND_H ... class Sound : public QIODevice { Q_OBJECT private: QMediaDevices *AllMediaDevices = nullpointer; QAudioDevice DefaultAudioOutputDevice; public: Sound(); }; // <- Closing curly brace and semicolon are missing! #endif // SOUND_H
Please add the
};
before the#endif
and try again.Regards