I'm trying build Qt project in MSVC 2019.
I installed Qt VS Tools v.2.10.1 (rev. 2), opened my Qt-project in MSVC through Qt VS Tools. But when I try to build it I keep getting the same error:
"E2422 defaulted default constructor cannot be constexpr because the corresponding implicitly declared default constructor would not be constexpr" in Qt-library file QtCore\qrunnable.h:
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QRUNNABLE_H
#define QRUNNABLE_H
#include <QtCore/qglobal.h>
#include <functional>
QT_BEGIN_NAMESPACE
class Q_CORE_EXPORT QRunnable
{
bool m_autoDelete = true;
Q_DISABLE_COPY(QRunnable)
public:
virtual void run() = 0;
constexpr QRunnable() noexcept = default; //<- error message points here
virtual ~QRunnable();
static QRunnable *create(std::function<void()> functionToRun);
bool autoDelete() const { return m_autoDelete; }
void setAutoDelete(bool autoDelete) { m_autoDelete = autoDelete; }
};
QT_END_NAMESPACE
#endif
In VC-project settings everything seems to be well (additional libraries and directories).
Can anyone tell me some hint how can I fix that?
Thanks a lot in advance!
I tried different Qt versions for MSVC 2019
:
5.15.2_msvc2019_64,
6.2.4_msvc2019_64,
6.3.2_msvc2019_64,
6.4.2_msvc2019_64,
but error is still here.
Related
I am using Qt 5.12.2 with MinGW 7.3.0 on Windows 10 x64.
I want to use Allied Vision Vimba SDK but get this error message when I want to compile:
C:\Program Files\Allied Vision\Vimba_3.1\VimbaCPP\Include\IFeatureObserver.h:59: Fehler: function 'AVT::VmbAPI::IFeatureObserver::~IFeatureObserver()' definition is marked dllimport
IMEXPORT virtual ~IFeatureObserver() {}
^
IFeatureObserver.h:
#ifndef AVT_VMBAPI_IFEATUREOBSERVER_H
#define AVT_VMBAPI_IFEATUREOBSERVER_H
#include <VimbaCPP/Include/VimbaCPPCommon.h>
#include <VimbaCPP/Include/SharedPointerDefines.h>
#include <VimbaCPP/Include/Feature.h>
#include <vector>
namespace AVT {
namespace VmbAPI {
class IFeatureObserver
{
public:
IMEXPORT virtual void FeatureChanged( const FeaturePtr &pFeature ) = 0;
IMEXPORT virtual ~IFeatureObserver() {}
protected:
IMEXPORT IFeatureObserver() {}
IMEXPORT IFeatureObserver( const IFeatureObserver& ) { /* No copy ctor */ }
};
typedef std::vector<IFeatureObserverPtr> IFeatureObserverPtrVector;
}} // namespace AVT::VmbAPI
#endif
This exact same problem was already posted here, but I think I should not open a 6 years old thread.
As discribed here https://stackoverflow.com/a/20644594/8010301 this problem seems to be solved already.
But I don't really know what to do.
Like egur said, I have to define the macro AVT_VMBAPI_CPP_EXPORTS in my makefile.
How to define this Macro and where(.pro file of my project or the Makefile inside the Build dir of my Project)? A small guid or an example would be very kind.
I am quite new to c++ and especially developing in Windows. I hope I can find help here.
i'm trying to build google v8 using visual studio 2019(i'm able to build using official steps with clang), and got below error:
Error C2027 use of undefined type “v8::internal::Object" v8_base_without_compiler E:\v8\src\handles\handles.h 144
V8_INLINE T operator*() const {
// unchecked_cast because we rather trust Handle<T> to contain a T than
// include all the respective -inl.h headers for SLOW_DCHECKs.
SLOW_DCHECK(IsDereferenceAllowed(INCLUDE_DEFERRED_CHECK));
return T::unchecked_cast(Object(*location())); // error on this line
}
my understanding of this part is, handles.h includes objects.h and has forward declaration for class Object (from objects.h), and inline operator method is calling Object constructor, which leads to c2027 use of undefined type v8::internal::Object
i created a simple c++ project with visual studio 2019 to reproduce the same error message
handles.h
#ifndef HANDLES_H_
#define HANDLES_H_
// forward declaration
class Object;
class Handle {
public:
__forceinline void* op() {
return new Object(0); // error here c2027 use of undefined type "Object"
}
void dummy();
};
#endif
objects.h
#ifndef OBJECTS_H_
#define OBJECTS_H_
class Object {
public:
explicit Object(int n):_n(n) {
}
void dummy();
int _n;
};
#endif
which is similar logic, an inline method implementation calls another class constructor
i don't understand how google's official steps with gn and clang could compile through the whole project, but msvc errors out
how to make it work for visual studio 2019? thanks!
I'm copying #JVApen's comment as answer
add #include "ojbects.h" will fix the issue
and if you're trying to build google's v8 using visual studio 2019, add #include "objects/objects.h" in handles/handles.h, then it will compile through
I need to convert Qt legacy code from 4.7 to 5.8, I have a compilation error in Qt Creator 4.2.1 Clang 7.0(Apple) 64bit. I'm using latest Qwt 6.1.3
Looking in .cpp file
#include "frmMainChart_UI.h"
#include <QHeaderView>
#include <qwt_plot_layout.h>
#include <qwt_legend.h>
#include "mpiDateScale.h"
#include "mpiPercentScale.h"
void frmMainChart_UI::setupUI(QWidget *parent_)
{
frmMainTableViewTree_UI::setupUI(QMap<int, QString>(), false, parent_);
delete frmMainTableViewTree_UI::tableCopy;
delete frmMainTableViewTree_UI::table;
chart = new mpiChart(widget);
chart->setAxisScaleDraw(QwtPlot::xBottom, new mpiDateScale());
chart->setAxisScaleDraw(QwtPlot::yLeft, new mpiPercentScale());
chart->plotLayout()->setCanvasMargin(20);
chart->plotLayout()->setMargin(20); // BROKE convert Qt4 to Qt5
chartZoomer = new mpiPlotZoomer(chart->canvas()); // BROKE convert Qt4 to Qt5
chartLegend = new QwtLegend(chart);
chart->insertLegend(chartLegend, QwtPlot::RightLegend);
QLinearGradient grad(0, 0, 1, 1);
grad.setCoordinateMode(QGradient::StretchToDeviceMode);
grad.setColorAt(0, Qt::white);
grad.setColorAt(1, QColor(220, 220, 220));
2 Errors in .cpp
../src/ui/frmMainChart_UI.cpp:18:26: error: no member named 'setMargin' in 'QwtPlotLayout'
chart->plotLayout()->setMargin(20); // BROKE convert Qt4 to Qt5
../src/ui/frmMainChart_UI.cpp:19:23: error: no matching constructor for initialization of 'mpiPlotZoomer'
chartZoomer = new mpiPlotZoomer(chart->canvas()); // BROKE convert Qt4 to Qt5
^
5 warnings and 2 errors generated
make: *** [frmMainChart_UI.o] Error 1
06:58:25: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project mypersonalindex (kit: Desktop Qt 5.8.0 clang 64bit)
When executing step "Make"
06:58:25: Elapsed time: 00:01.
The Qwt 6.1.3 Docs has member function http://qwt.sourceforge.net/class_qwt_plot_layout.html
void setCanvasMargin (int margin, int axis=-1)
But NO Member Function being used
setMargin
My C++ skill is pretty limited, do you see any minor tweaks that could convert this from Qt4 to Qt5. ... so what is the replacement?
Looking at mpiChart.h likely relates to canvas() error
#ifndef MPICHART_H
#define MPICHART_H
#include "qwt_plot.h"
class mpiChart : public QwtPlot
{
Q_OBJECT
public:
mpiChart(QWidget *parent_ = 0):
QwtPlot(parent_)
{}
public slots:
void exportChart();
};
#endif // MPICHART_H
And Looking in mpiPlotZoomer.h relates to canvas() error
#ifndef MPIPLOTZOOMER_H
#define MPIPLOTZOOMER_H
#include <qwt_plot_zoomer.h>
#include <qwt_plot_canvas.h> // JDL convert Qt4 to Qt5
#include <qwt_compat.h> // JDL convert Qt4 to Qt5
class mpiPlotZoomer: public QwtPlotZoomer
{
public:
mpiPlotZoomer(QwtPlotCanvas *canvas_):
QwtPlotZoomer(canvas_, false)
{
setTrackerMode(AlwaysOn);
}
virtual QwtText trackerText(const QwtDoublePoint &pos_) const;
};
#endif // MPIPLOTZOOMER_H
As the setMargin function has been removed between Qwt version you were using for Qt 4.7 and Qwt 1.6.3 you are using with 5.8, you have no other choice than:
Replace setMargin calls by setCanvasMargin if that fits your needs
Or, remove setMargin calls
Try both, and see which one looks the best when displaying the GUI.
For the canvas() error, it's hard to tell without seeing mpiChart and mpiPlotZoomer declaration. However, I'll give it a try:
canvas() used to return a QwtPlotCanvas* in the past. For recent versions of Qwt it returns a QWidget*. So if your mpiPlotZoomer constructor expects a QwtPlotCanvas* as parameter, you'll have to:
Replace mpiPlotZoomer parameters type from QwtPlotCanvas* by QWidget*. May work if the guy who wrote the mpiPlotZoomer class does not actually use and QwtPlotCanvas members/attributes (he may only use it for parenting purpose)
Or replace mpiPlotZoomer(chart->canvas()); by mpiPlotZoomer( qobject_cast<QwtPlotCanvas*>( chart->canvas() ) ); which will hoepfully work fine.
I am trying to use the http://www.net-snmp.org library in my project but after it build it crashes without the chance to get debug information.
To be more clear:
I hit the run button -> Starting program.exe -> The program crashed without any output or window
I am using the Windows 7 64 bit, MSVC++ 2010 32 Bit compiler Qt5.0.2 and the binaries for net-snmp from
http://softlayer-ams.dl.sourceforge.net/project/net-snmp/net-snmp%20binaries/5.7-binaries/net-snmp-5.7.0-1.x86.exe
I added these lines in my *.pro file to include the library
win32:INCLUDEPATH += "C:\snmp_5.7.0\include"
LIBS += -L"C:\snmp_5.7.0\lib" -lnetsnmp -lnetsnmpmibs -lnetsnmptrapd
and wanted to follow the "Simple application tutorial" (http://www.net-snmp.org/wiki/index.php/TUT:Simple_Application)
This is what I got so far:
snmpTest.h
#ifndef SNMPTEST_H
#define SNMPTEST_H
#include <QDebug>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/library/transform_oids.h>
class SnmpTest
{
public:
SnmpTest();
void doSnmp();
};
#endif // SNMPTEST_H
snmpTest.cpp
#include "snmptest.h"
SnmpTest::SnmpTest()
{
}
void SnmpTest::doSnmp()
{
const char *our_v3_passphrase = "XXXX";
struct snmp_session session, *ss;
struct snmp_pdu *pdu;
struct snmp_pdu *response;
oid anOID[MAX_OID_LEN];
size_t anOID_len = MAX_OID_LEN;
struct variable_list *vars;
int status;
/*
* Initialize the SNMP library
*/
init_snmp("app");
}
If I remove the line
init_snmp("app");
It builds and runs just fine.
I solved the problem by compiling the libary by myselfe
I also encountered this problem, first of all need to compile the net-snmp library, and then compile the netsnmp.dll need to be placed under the program executable file directory.
Disclaimer: everything works fine on Linux. On Windows, I have recently changed from MinGW to MSVC2012 because I couldn't read MP3 properly (see Make the WMF plugin compile with MinGW.)
In my project, I have :
Core (DLL)
Another DLL built using Core
A Media Player (the Qt App, using both DLL and loading plugins)
To keep my project cross-platform, I also extracted Windows specific features (progress bar, thumbnail buttons) into a 3rd party plugin. In fact, I'm starting to write a plugin manager, which loads/unloads plugin at runtime and without restarting the app, it's working fine.
But since I've switched to MSVC, I cannot build my plugins anymore. I'm facing:
C4273: 'staticMetaObject' : inconsistent dll linkage
I don't know how to proceed... I have the following structure:
In MainProject\Core\Interfaces
class MIAMCORE_LIBRARY MediaPlayerPluginInterface : public BasicPluginInterface
{
public:
virtual ~MediaPlayerPluginInterface() {}
virtual void setMediaPlayer(QWeakPointer<MediaPlayer>) = 0;
virtual bool providesView() const = 0;
virtual void toggleViews(QWidget *) {}
};
In Plugin.h
class Minimode : public QWidget, public MediaPlayerPluginInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID MediaPlayerPluginInterface_iid)
Q_INTERFACES(MediaPlayerPluginInterface)
private:
Ui::ConfigForm _ui;
QWeakPointer<MediaPlayer> _mediaPlayer;
bool _startMoving;
QPoint _pos, _globalPos;
public:
explicit Minimode();
virtual ~Minimode();
inline virtual QString name() const { return "Minimode"; }
inline virtual QString version() const { return "1.0"; }
inline virtual bool providesView() const { return true; }
virtual QWidget* configPage();
virtual void setMediaPlayer(QWeakPointer<MediaPlayer> mediaPlayer);
virtual void toggleViews(QWidget *view);
protected:
/** Redefined to be able to drag this widget on screen. */
void mouseMoveEvent(QMouseEvent *e);
/** Redefined to be able to drag this widget on screen. */
void mouseReleaseEvent(QMouseEvent *e);
void mousePressEvent(QMouseEvent *e);
private:
void applyColorToStandardIcon(QPushButton *button);
};
My Plugin.pro
QT += widgets multimedia
TARGET = $$qtLibraryTarget(mini-mode)
TEMPLATE = lib
MiamPlayerBuildDirectory = C:\dev\Miam-Player\build\MiamPlayer
DEFINES += MINIMODE_MIAMPLUGIN
CONFIG += c++11
CONFIG(debug, debug|release) {
target.path = $$MiamPlayerBuildDirectory\debug\plugins
LIBS += -Ldebug -lMiamCore
}
INSTALLS += target
Miamcore_global.h
#ifndef MIAMCORE_GLOBAL_H
#define MIAMCORE_GLOBAL_H
#include <QtCore/QtGlobal>
#if defined(MIAMCORE_LIBRARY)
#undef MIAMCORE_LIBRARY
#define MIAMCORE_LIBRARY Q_DECL_EXPORT
#else
#define MIAMCORE_LIBRARY Q_DECL_IMPORT
#endif
#endif // MIAMCORE_GLOBAL_H
I have tried various permutations with the macro MIAMCORE_LIBRARY, and with another MINIMODE_PLUGIN but none of them worked (between class and Minimode but not shown above). Should I add specific keywords in my *.pro files ?
Your macro seems to be wrong for the export and import.
Provided, you do not need static building for the plugins which is a somewhat real expectation since those are meant to be dynamic libraries, you should use your macro like below.
Please also note that, you forgot to include the global Qt header where the import and export macro are defined.
Miamcore_global.h
#ifndef MIAMCORE_GLOBAL_H
#define MIAMCORE_GLOBAL_H
#include <QtCore/qglobal.h>
#ifdef MINIMODE_MIAMPLUGIN
# define MIAMCORE_LIBRARY Q_DECL_EXPORT
#else
# define MIAMCORE_LIBRARY Q_DECL_IMPORT
#endif
#endif // MIAMCORE_GLOBAL_H
Then you will need to specify the following define in your project file:
YourPlugin.pro
...
DEFINES += MINIMODE_MIAMPLUGIN
...
This design works fine in our plugin architecture with Qt 4 as well as Qt 5 on Windows and Unix.
The import thing is Windows here. It would be just fine on Linux without this, but for Windows, you need to make sure to export the plugins when building it, but import when you are actually using it.
That is why you need to pass the desired designation to the project file that this build time, export it. Once, your users will use the plugin, this define will not be there anymore, and then it will be imported.