No rule needed to make target .mocWhy is important to include “.moc” file at end of a Qt Source code file?Including a cpp file in a header file without multiple definitionWhat are the rules for calling the superclass constructor?What are the rules about using an underscore in a C++ identifier?Do the parentheses after the type name make a difference with new?Why do we need virtual functions in C++?What is The Rule of Three?What are the basic rules and idioms for operator overloading?Iterator invalidation rulesQt 5 cmake fails with undefined reference to vtable on hello world with inc & src as subdirsAdd include directories to AUTOMOCEclipse and qmake
Traveling from Germany to other countries by train?
Is the first page of a novel really that important?
The meaning of "scale" in "because diversions scale so easily wealth becomes concentrated"
Did Captain America make out with his niece?
How does LIDAR avoid getting confused in an environment being scanned by hundreds of other LIDAR?
Our group keeps dying during the Lost Mine of Phandelver campaign. What are we doing wrong?
Getting an entry level IT position later in life
Based on what criteria do you add/not add icons to labels within a toolbar?
Why do scoped enums allow use of | operator when initializing using previously assigned values?
How easy is it to get a gun illegally in the United States?
Purchased new computer from DELL with pre-installed Ubuntu. Won't boot. Should assume its an error from DELL?
Launch capabilities of GSLV Mark III
Why do cheap flights with a layover get more expensive when you split them up into separate flights?
Does the length of a password for Wi-Fi affect speed?
Pronouns when writing from the point of view of a robot
What is it exactly about flying a Flyboard across the English channel that made Zapata's thighs burn?
In MTG, was there ever a five-color deck that worked well?
What are the function of EM and EN spaces?
What's going on with an item that starts with an hbox?
Is there a way to say "double + any number" in German?
Best way to explain to my boss that I cannot attend a team summit because it is on Rosh Hashana or any other Jewish Holiday
What is the probability of a biased coin coming up heads given that a liar is claiming that the coin came up heads?
Not been paid even after reminding the Treasurer; what should I do?
Is a switch from R to Python worth it?
No rule needed to make target .moc
Why is important to include “.moc” file at end of a Qt Source code file?Including a cpp file in a header file without multiple definitionWhat are the rules for calling the superclass constructor?What are the rules about using an underscore in a C++ identifier?Do the parentheses after the type name make a difference with new?Why do we need virtual functions in C++?What is The Rule of Three?What are the basic rules and idioms for operator overloading?Iterator invalidation rulesQt 5 cmake fails with undefined reference to vtable on hello world with inc & src as subdirsAdd include directories to AUTOMOCEclipse and qmake
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to turn ovpn3's ovpncli example into a class that derives from QObject. I'm unable to turn the source file into a separate interface (.h) and implementation (.cpp) file. To make the MOC happy, I've put #include "openvpn.moc"
at the end of openvpn.cpp (the source file). I am getting this error however: :-1: error: No rule to make target 'openvpn.moc', needed by 'openvpnmanager.o'. Stop.
I've cleaned the build directory, re-ran qmake, and rebuilt it 1000 times. Despite this, it still refuses to work. What am I doing wrong?
myproject.pro:
QT += core widgets network
CONFIG += c++11
UI_SOURCES_DIR = src/gui
UI_HEADERS_DIR = include
. . .
SOURCES +=
src/main.cpp
src/gui/loginwindow.cpp
src/api/api.cpp
src/openvpn/openvpn.cpp
src/alert.cpp
src/gui/vpn.cpp
src/api/account.cpp
src/crypto.cpp
src/killswitch.cpp
src/vpnstatus.cpp
src/gui/logdialog.cpp
src/logitem.cpp
src/authenticationworker.cpp
src/api/error.cpp
src/openvpn/openvpnmanager.cpp
src/api/server.cpp
src/api/authenticationresponse.cpp
HEADERS +=
include/loginwindow.h
include/api.h
include/alert.h
include/vpn.h
include/account.h
include/crypto.h
include/killswitch.h
include/configtype.h
include/vpnstatus.h
include/connectionstatus.h
include/loglevel.h
include/logdialog.h
include/logitem.h
include/authenticationworker.h
include/error.h
include/openvpnmanager.h
include/server.h
include/authenticationresponse.h
FORMS +=
src/gui/loginwindow.ui
src/gui/vpn.ui
src/gui/logdialog.ui
RESOURCES +=
src/resources.qrc
DISTFILES +=
openvpn.cpp:
class Client : public QObject, public ClientAPI::OpenVPNClient {
Q_OBJECT
public:
. . .
c++ qt openvpn
add a comment |
I am trying to turn ovpn3's ovpncli example into a class that derives from QObject. I'm unable to turn the source file into a separate interface (.h) and implementation (.cpp) file. To make the MOC happy, I've put #include "openvpn.moc"
at the end of openvpn.cpp (the source file). I am getting this error however: :-1: error: No rule to make target 'openvpn.moc', needed by 'openvpnmanager.o'. Stop.
I've cleaned the build directory, re-ran qmake, and rebuilt it 1000 times. Despite this, it still refuses to work. What am I doing wrong?
myproject.pro:
QT += core widgets network
CONFIG += c++11
UI_SOURCES_DIR = src/gui
UI_HEADERS_DIR = include
. . .
SOURCES +=
src/main.cpp
src/gui/loginwindow.cpp
src/api/api.cpp
src/openvpn/openvpn.cpp
src/alert.cpp
src/gui/vpn.cpp
src/api/account.cpp
src/crypto.cpp
src/killswitch.cpp
src/vpnstatus.cpp
src/gui/logdialog.cpp
src/logitem.cpp
src/authenticationworker.cpp
src/api/error.cpp
src/openvpn/openvpnmanager.cpp
src/api/server.cpp
src/api/authenticationresponse.cpp
HEADERS +=
include/loginwindow.h
include/api.h
include/alert.h
include/vpn.h
include/account.h
include/crypto.h
include/killswitch.h
include/configtype.h
include/vpnstatus.h
include/connectionstatus.h
include/loglevel.h
include/logdialog.h
include/logitem.h
include/authenticationworker.h
include/error.h
include/openvpnmanager.h
include/server.h
include/authenticationresponse.h
FORMS +=
src/gui/loginwindow.ui
src/gui/vpn.ui
src/gui/logdialog.ui
RESOURCES +=
src/resources.qrc
DISTFILES +=
openvpn.cpp:
class Client : public QObject, public ClientAPI::OpenVPNClient {
Q_OBJECT
public:
. . .
c++ qt openvpn
add a comment |
I am trying to turn ovpn3's ovpncli example into a class that derives from QObject. I'm unable to turn the source file into a separate interface (.h) and implementation (.cpp) file. To make the MOC happy, I've put #include "openvpn.moc"
at the end of openvpn.cpp (the source file). I am getting this error however: :-1: error: No rule to make target 'openvpn.moc', needed by 'openvpnmanager.o'. Stop.
I've cleaned the build directory, re-ran qmake, and rebuilt it 1000 times. Despite this, it still refuses to work. What am I doing wrong?
myproject.pro:
QT += core widgets network
CONFIG += c++11
UI_SOURCES_DIR = src/gui
UI_HEADERS_DIR = include
. . .
SOURCES +=
src/main.cpp
src/gui/loginwindow.cpp
src/api/api.cpp
src/openvpn/openvpn.cpp
src/alert.cpp
src/gui/vpn.cpp
src/api/account.cpp
src/crypto.cpp
src/killswitch.cpp
src/vpnstatus.cpp
src/gui/logdialog.cpp
src/logitem.cpp
src/authenticationworker.cpp
src/api/error.cpp
src/openvpn/openvpnmanager.cpp
src/api/server.cpp
src/api/authenticationresponse.cpp
HEADERS +=
include/loginwindow.h
include/api.h
include/alert.h
include/vpn.h
include/account.h
include/crypto.h
include/killswitch.h
include/configtype.h
include/vpnstatus.h
include/connectionstatus.h
include/loglevel.h
include/logdialog.h
include/logitem.h
include/authenticationworker.h
include/error.h
include/openvpnmanager.h
include/server.h
include/authenticationresponse.h
FORMS +=
src/gui/loginwindow.ui
src/gui/vpn.ui
src/gui/logdialog.ui
RESOURCES +=
src/resources.qrc
DISTFILES +=
openvpn.cpp:
class Client : public QObject, public ClientAPI::OpenVPNClient {
Q_OBJECT
public:
. . .
c++ qt openvpn
I am trying to turn ovpn3's ovpncli example into a class that derives from QObject. I'm unable to turn the source file into a separate interface (.h) and implementation (.cpp) file. To make the MOC happy, I've put #include "openvpn.moc"
at the end of openvpn.cpp (the source file). I am getting this error however: :-1: error: No rule to make target 'openvpn.moc', needed by 'openvpnmanager.o'. Stop.
I've cleaned the build directory, re-ran qmake, and rebuilt it 1000 times. Despite this, it still refuses to work. What am I doing wrong?
myproject.pro:
QT += core widgets network
CONFIG += c++11
UI_SOURCES_DIR = src/gui
UI_HEADERS_DIR = include
. . .
SOURCES +=
src/main.cpp
src/gui/loginwindow.cpp
src/api/api.cpp
src/openvpn/openvpn.cpp
src/alert.cpp
src/gui/vpn.cpp
src/api/account.cpp
src/crypto.cpp
src/killswitch.cpp
src/vpnstatus.cpp
src/gui/logdialog.cpp
src/logitem.cpp
src/authenticationworker.cpp
src/api/error.cpp
src/openvpn/openvpnmanager.cpp
src/api/server.cpp
src/api/authenticationresponse.cpp
HEADERS +=
include/loginwindow.h
include/api.h
include/alert.h
include/vpn.h
include/account.h
include/crypto.h
include/killswitch.h
include/configtype.h
include/vpnstatus.h
include/connectionstatus.h
include/loglevel.h
include/logdialog.h
include/logitem.h
include/authenticationworker.h
include/error.h
include/openvpnmanager.h
include/server.h
include/authenticationresponse.h
FORMS +=
src/gui/loginwindow.ui
src/gui/vpn.ui
src/gui/logdialog.ui
RESOURCES +=
src/resources.qrc
DISTFILES +=
openvpn.cpp:
class Client : public QObject, public ClientAPI::OpenVPNClient {
Q_OBJECT
public:
. . .
c++ qt openvpn
c++ qt openvpn
edited Mar 27 at 23:51
Chase
asked Mar 27 at 3:50
ChaseChase
336 bronze badges
336 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
TL;DR
Simply delete your build-xxx
folder, and rebuild from scratch!
Context
You (almost) never have to include a .moc
file. Moc files are created automatically by the moc
ompiler and compiled and linked in a dedicated translation unit (i.e. like any .cpp
file).
The only exception is when your QObject
class is declared in a cpp
file (which happens to be your case!), because the .moc
implementation will still require your class definition to compile. As suggested in the comments, there is a detailed explanation here.
Potential issues
Regarding your specific issue, moc
file issues can originate from:
- the
Q_OBJECT
keyword is missing (but you have it). This token is used to trigger the generation of a.moc
file for that specific class. Without it, most QObject features are missing. - the class was parsed/compiled previously without the
Q_OBJECT
keyword, and cached as a non-QObject class. In that case, you just have to manually delete your build folder (or runqmake
manually), to force identifying again which classes should bemoc
ed. - You are using the wrong filename for your
moc
ed file. The correct name is typicallymoc_filename.cpp
when your class is declared in a header filefilename.moc
when your class is declared in a source file
qmake
does not actually parses your.cpp
file. This can be the case if your.pro
file doesn't include it in theSOURCES
variable, or if you are just never runningqmake
(specific setup, etc.)
Sample Makefile
You can double check it your moc
files has appropriate rules in the Makefile of its project. Below is a sample portion of a Makefile:
compiler_moc_source_make_all: mysourcefile.moc
compiler_moc_source_clean:
-$(DEL_FILE) mysourcefile.moc
mysourcefile.moc: /home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/QCoreApplication
/home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/qcoreapplication.h
/home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/qglobal.h
/home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/qconfig-bootstrapped.h
# [...] more includes
/home/aleravat/Qt/5.9.7/gcc_64/bin/moc $(DEFINES) --include ./moc_predefs.h [...] mysourcefile.cpp -o mysourcefile.moc
Clarification: you must include moc in the cpp file manually if you place QObject derived class into a cpp file. See good explanation from here
– talamaki
Mar 27 at 21:52
Oh thanks! I actually didn't see that the OP had his class definition in a.cpp
file. That was the reason of my "(almost) never", but I guess it totally makes sense to explain it now.
– Adrien Leravat
Mar 27 at 21:57
I'm looking at my Makefile generated by Qt's qmake and there is no moc_openvpn.cpp anywhere. In the 3rd bulletpoint are you suggesting that openvpn.cpp must be renamed?
– Chase
Mar 27 at 23:45
You're defining your class in a cpp file, so your original name is probably the right one,openvpn.moc
. Do you see any reference to that particular one or any variation aroundopenvpn
? Are you sure that your file is listed in theSOURCES
variable of your.pro
as well?
– Adrien Leravat
Mar 28 at 0:15
These two files are included in my Makefile under openvpnmanager.o (openvpnmanager.cpp includes openvpn.cpp):src/openvpn/openvpn.cpp openvpn.moc
– Chase
Mar 28 at 0:46
|
show 7 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55369520%2fno-rule-needed-to-make-target-moc%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
TL;DR
Simply delete your build-xxx
folder, and rebuild from scratch!
Context
You (almost) never have to include a .moc
file. Moc files are created automatically by the moc
ompiler and compiled and linked in a dedicated translation unit (i.e. like any .cpp
file).
The only exception is when your QObject
class is declared in a cpp
file (which happens to be your case!), because the .moc
implementation will still require your class definition to compile. As suggested in the comments, there is a detailed explanation here.
Potential issues
Regarding your specific issue, moc
file issues can originate from:
- the
Q_OBJECT
keyword is missing (but you have it). This token is used to trigger the generation of a.moc
file for that specific class. Without it, most QObject features are missing. - the class was parsed/compiled previously without the
Q_OBJECT
keyword, and cached as a non-QObject class. In that case, you just have to manually delete your build folder (or runqmake
manually), to force identifying again which classes should bemoc
ed. - You are using the wrong filename for your
moc
ed file. The correct name is typicallymoc_filename.cpp
when your class is declared in a header filefilename.moc
when your class is declared in a source file
qmake
does not actually parses your.cpp
file. This can be the case if your.pro
file doesn't include it in theSOURCES
variable, or if you are just never runningqmake
(specific setup, etc.)
Sample Makefile
You can double check it your moc
files has appropriate rules in the Makefile of its project. Below is a sample portion of a Makefile:
compiler_moc_source_make_all: mysourcefile.moc
compiler_moc_source_clean:
-$(DEL_FILE) mysourcefile.moc
mysourcefile.moc: /home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/QCoreApplication
/home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/qcoreapplication.h
/home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/qglobal.h
/home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/qconfig-bootstrapped.h
# [...] more includes
/home/aleravat/Qt/5.9.7/gcc_64/bin/moc $(DEFINES) --include ./moc_predefs.h [...] mysourcefile.cpp -o mysourcefile.moc
Clarification: you must include moc in the cpp file manually if you place QObject derived class into a cpp file. See good explanation from here
– talamaki
Mar 27 at 21:52
Oh thanks! I actually didn't see that the OP had his class definition in a.cpp
file. That was the reason of my "(almost) never", but I guess it totally makes sense to explain it now.
– Adrien Leravat
Mar 27 at 21:57
I'm looking at my Makefile generated by Qt's qmake and there is no moc_openvpn.cpp anywhere. In the 3rd bulletpoint are you suggesting that openvpn.cpp must be renamed?
– Chase
Mar 27 at 23:45
You're defining your class in a cpp file, so your original name is probably the right one,openvpn.moc
. Do you see any reference to that particular one or any variation aroundopenvpn
? Are you sure that your file is listed in theSOURCES
variable of your.pro
as well?
– Adrien Leravat
Mar 28 at 0:15
These two files are included in my Makefile under openvpnmanager.o (openvpnmanager.cpp includes openvpn.cpp):src/openvpn/openvpn.cpp openvpn.moc
– Chase
Mar 28 at 0:46
|
show 7 more comments
TL;DR
Simply delete your build-xxx
folder, and rebuild from scratch!
Context
You (almost) never have to include a .moc
file. Moc files are created automatically by the moc
ompiler and compiled and linked in a dedicated translation unit (i.e. like any .cpp
file).
The only exception is when your QObject
class is declared in a cpp
file (which happens to be your case!), because the .moc
implementation will still require your class definition to compile. As suggested in the comments, there is a detailed explanation here.
Potential issues
Regarding your specific issue, moc
file issues can originate from:
- the
Q_OBJECT
keyword is missing (but you have it). This token is used to trigger the generation of a.moc
file for that specific class. Without it, most QObject features are missing. - the class was parsed/compiled previously without the
Q_OBJECT
keyword, and cached as a non-QObject class. In that case, you just have to manually delete your build folder (or runqmake
manually), to force identifying again which classes should bemoc
ed. - You are using the wrong filename for your
moc
ed file. The correct name is typicallymoc_filename.cpp
when your class is declared in a header filefilename.moc
when your class is declared in a source file
qmake
does not actually parses your.cpp
file. This can be the case if your.pro
file doesn't include it in theSOURCES
variable, or if you are just never runningqmake
(specific setup, etc.)
Sample Makefile
You can double check it your moc
files has appropriate rules in the Makefile of its project. Below is a sample portion of a Makefile:
compiler_moc_source_make_all: mysourcefile.moc
compiler_moc_source_clean:
-$(DEL_FILE) mysourcefile.moc
mysourcefile.moc: /home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/QCoreApplication
/home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/qcoreapplication.h
/home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/qglobal.h
/home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/qconfig-bootstrapped.h
# [...] more includes
/home/aleravat/Qt/5.9.7/gcc_64/bin/moc $(DEFINES) --include ./moc_predefs.h [...] mysourcefile.cpp -o mysourcefile.moc
Clarification: you must include moc in the cpp file manually if you place QObject derived class into a cpp file. See good explanation from here
– talamaki
Mar 27 at 21:52
Oh thanks! I actually didn't see that the OP had his class definition in a.cpp
file. That was the reason of my "(almost) never", but I guess it totally makes sense to explain it now.
– Adrien Leravat
Mar 27 at 21:57
I'm looking at my Makefile generated by Qt's qmake and there is no moc_openvpn.cpp anywhere. In the 3rd bulletpoint are you suggesting that openvpn.cpp must be renamed?
– Chase
Mar 27 at 23:45
You're defining your class in a cpp file, so your original name is probably the right one,openvpn.moc
. Do you see any reference to that particular one or any variation aroundopenvpn
? Are you sure that your file is listed in theSOURCES
variable of your.pro
as well?
– Adrien Leravat
Mar 28 at 0:15
These two files are included in my Makefile under openvpnmanager.o (openvpnmanager.cpp includes openvpn.cpp):src/openvpn/openvpn.cpp openvpn.moc
– Chase
Mar 28 at 0:46
|
show 7 more comments
TL;DR
Simply delete your build-xxx
folder, and rebuild from scratch!
Context
You (almost) never have to include a .moc
file. Moc files are created automatically by the moc
ompiler and compiled and linked in a dedicated translation unit (i.e. like any .cpp
file).
The only exception is when your QObject
class is declared in a cpp
file (which happens to be your case!), because the .moc
implementation will still require your class definition to compile. As suggested in the comments, there is a detailed explanation here.
Potential issues
Regarding your specific issue, moc
file issues can originate from:
- the
Q_OBJECT
keyword is missing (but you have it). This token is used to trigger the generation of a.moc
file for that specific class. Without it, most QObject features are missing. - the class was parsed/compiled previously without the
Q_OBJECT
keyword, and cached as a non-QObject class. In that case, you just have to manually delete your build folder (or runqmake
manually), to force identifying again which classes should bemoc
ed. - You are using the wrong filename for your
moc
ed file. The correct name is typicallymoc_filename.cpp
when your class is declared in a header filefilename.moc
when your class is declared in a source file
qmake
does not actually parses your.cpp
file. This can be the case if your.pro
file doesn't include it in theSOURCES
variable, or if you are just never runningqmake
(specific setup, etc.)
Sample Makefile
You can double check it your moc
files has appropriate rules in the Makefile of its project. Below is a sample portion of a Makefile:
compiler_moc_source_make_all: mysourcefile.moc
compiler_moc_source_clean:
-$(DEL_FILE) mysourcefile.moc
mysourcefile.moc: /home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/QCoreApplication
/home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/qcoreapplication.h
/home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/qglobal.h
/home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/qconfig-bootstrapped.h
# [...] more includes
/home/aleravat/Qt/5.9.7/gcc_64/bin/moc $(DEFINES) --include ./moc_predefs.h [...] mysourcefile.cpp -o mysourcefile.moc
TL;DR
Simply delete your build-xxx
folder, and rebuild from scratch!
Context
You (almost) never have to include a .moc
file. Moc files are created automatically by the moc
ompiler and compiled and linked in a dedicated translation unit (i.e. like any .cpp
file).
The only exception is when your QObject
class is declared in a cpp
file (which happens to be your case!), because the .moc
implementation will still require your class definition to compile. As suggested in the comments, there is a detailed explanation here.
Potential issues
Regarding your specific issue, moc
file issues can originate from:
- the
Q_OBJECT
keyword is missing (but you have it). This token is used to trigger the generation of a.moc
file for that specific class. Without it, most QObject features are missing. - the class was parsed/compiled previously without the
Q_OBJECT
keyword, and cached as a non-QObject class. In that case, you just have to manually delete your build folder (or runqmake
manually), to force identifying again which classes should bemoc
ed. - You are using the wrong filename for your
moc
ed file. The correct name is typicallymoc_filename.cpp
when your class is declared in a header filefilename.moc
when your class is declared in a source file
qmake
does not actually parses your.cpp
file. This can be the case if your.pro
file doesn't include it in theSOURCES
variable, or if you are just never runningqmake
(specific setup, etc.)
Sample Makefile
You can double check it your moc
files has appropriate rules in the Makefile of its project. Below is a sample portion of a Makefile:
compiler_moc_source_make_all: mysourcefile.moc
compiler_moc_source_clean:
-$(DEL_FILE) mysourcefile.moc
mysourcefile.moc: /home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/QCoreApplication
/home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/qcoreapplication.h
/home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/qglobal.h
/home/aleravat/Qt/5.9.7/gcc_64/include/QtCore/qconfig-bootstrapped.h
# [...] more includes
/home/aleravat/Qt/5.9.7/gcc_64/bin/moc $(DEFINES) --include ./moc_predefs.h [...] mysourcefile.cpp -o mysourcefile.moc
edited Mar 28 at 0:16
answered Mar 27 at 4:11
Adrien LeravatAdrien Leravat
1,62610 silver badges24 bronze badges
1,62610 silver badges24 bronze badges
Clarification: you must include moc in the cpp file manually if you place QObject derived class into a cpp file. See good explanation from here
– talamaki
Mar 27 at 21:52
Oh thanks! I actually didn't see that the OP had his class definition in a.cpp
file. That was the reason of my "(almost) never", but I guess it totally makes sense to explain it now.
– Adrien Leravat
Mar 27 at 21:57
I'm looking at my Makefile generated by Qt's qmake and there is no moc_openvpn.cpp anywhere. In the 3rd bulletpoint are you suggesting that openvpn.cpp must be renamed?
– Chase
Mar 27 at 23:45
You're defining your class in a cpp file, so your original name is probably the right one,openvpn.moc
. Do you see any reference to that particular one or any variation aroundopenvpn
? Are you sure that your file is listed in theSOURCES
variable of your.pro
as well?
– Adrien Leravat
Mar 28 at 0:15
These two files are included in my Makefile under openvpnmanager.o (openvpnmanager.cpp includes openvpn.cpp):src/openvpn/openvpn.cpp openvpn.moc
– Chase
Mar 28 at 0:46
|
show 7 more comments
Clarification: you must include moc in the cpp file manually if you place QObject derived class into a cpp file. See good explanation from here
– talamaki
Mar 27 at 21:52
Oh thanks! I actually didn't see that the OP had his class definition in a.cpp
file. That was the reason of my "(almost) never", but I guess it totally makes sense to explain it now.
– Adrien Leravat
Mar 27 at 21:57
I'm looking at my Makefile generated by Qt's qmake and there is no moc_openvpn.cpp anywhere. In the 3rd bulletpoint are you suggesting that openvpn.cpp must be renamed?
– Chase
Mar 27 at 23:45
You're defining your class in a cpp file, so your original name is probably the right one,openvpn.moc
. Do you see any reference to that particular one or any variation aroundopenvpn
? Are you sure that your file is listed in theSOURCES
variable of your.pro
as well?
– Adrien Leravat
Mar 28 at 0:15
These two files are included in my Makefile under openvpnmanager.o (openvpnmanager.cpp includes openvpn.cpp):src/openvpn/openvpn.cpp openvpn.moc
– Chase
Mar 28 at 0:46
Clarification: you must include moc in the cpp file manually if you place QObject derived class into a cpp file. See good explanation from here
– talamaki
Mar 27 at 21:52
Clarification: you must include moc in the cpp file manually if you place QObject derived class into a cpp file. See good explanation from here
– talamaki
Mar 27 at 21:52
Oh thanks! I actually didn't see that the OP had his class definition in a
.cpp
file. That was the reason of my "(almost) never", but I guess it totally makes sense to explain it now.– Adrien Leravat
Mar 27 at 21:57
Oh thanks! I actually didn't see that the OP had his class definition in a
.cpp
file. That was the reason of my "(almost) never", but I guess it totally makes sense to explain it now.– Adrien Leravat
Mar 27 at 21:57
I'm looking at my Makefile generated by Qt's qmake and there is no moc_openvpn.cpp anywhere. In the 3rd bulletpoint are you suggesting that openvpn.cpp must be renamed?
– Chase
Mar 27 at 23:45
I'm looking at my Makefile generated by Qt's qmake and there is no moc_openvpn.cpp anywhere. In the 3rd bulletpoint are you suggesting that openvpn.cpp must be renamed?
– Chase
Mar 27 at 23:45
You're defining your class in a cpp file, so your original name is probably the right one,
openvpn.moc
. Do you see any reference to that particular one or any variation around openvpn
? Are you sure that your file is listed in the SOURCES
variable of your .pro
as well?– Adrien Leravat
Mar 28 at 0:15
You're defining your class in a cpp file, so your original name is probably the right one,
openvpn.moc
. Do you see any reference to that particular one or any variation around openvpn
? Are you sure that your file is listed in the SOURCES
variable of your .pro
as well?– Adrien Leravat
Mar 28 at 0:15
These two files are included in my Makefile under openvpnmanager.o (openvpnmanager.cpp includes openvpn.cpp):
src/openvpn/openvpn.cpp openvpn.moc
– Chase
Mar 28 at 0:46
These two files are included in my Makefile under openvpnmanager.o (openvpnmanager.cpp includes openvpn.cpp):
src/openvpn/openvpn.cpp openvpn.moc
– Chase
Mar 28 at 0:46
|
show 7 more comments
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55369520%2fno-rule-needed-to-make-target-moc%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown