I've created a custom widget to include in a project of mine. QtDesigner loads the plugin correctly and under Tools -> Form Editor -> About Qt Creator Plugins it says it has loaded correctly - but here's the thing, it does not compile. I can drag it into my design form, it shows up correctly, but upon compiling it fails with the error:
[...]/ui_itemview.h:13: error: QtWidgets/QAction: No such file or directory
at the line
#include <QtWidgets/QAction>
So, according to this error, it seems that Qt Creator doesn't find it's own libraries which are included in a file that was automatically created (namely: "ui_itemview.h")?
The things I have tried until now:
-
At first the plugin couldn't even load into QtDesigner, which I fixed by changing some lines of code which were for an older version of Qt (I have found so many outdated tutorials, it isn't even funny anymore)
-
After QtDesigner correctly loaded my plugin I tried including it into my project, which worked in Design mode, but upon trying to compile it showed me some errors about not knowing of the .cpp and .h files of the plugin.
-
I read somewhere, that the .so file that is included in the plugins folder for QtDesigner only includes information for Qt, but not the source and header files, so I just threw the plugins source and header files into my project directory and some automatically generated files in the build directory and included them in the .pro file (should I have done this? If not, how else?), which resolved that error, but...
-
...the error shown above popped up. Which I just can't comprehend - it does not show me in code that the file is unknown (it would underline it if unknown, which is not the case), but it apparently doesn't know it...?
-
After that I just tried random things and with changing
#include <QtWidgets/QAction>
to
#include <QAction>
it stopped showing me that error, but instead showed me the same error for the next include - I then proceeded to change this for all following includes
-
aaaaand the next error: Qt doesn't know "QStringLiteral" anymore
-
after that I reverted back to the original code, because I'm not really keen on messing with automatically generated files and since it doesn't fix the problem I just left it like it was.
-
and during all those errors I have used all the google-fu I could manage
I have mostly sticked to this tutorial, but some information came from everywhere, I can't really say every source I've looked into.
PS: English is not my first language, I hope I haven't rambled too much :D
PPS: It probably is worth noting, that the plugin itself does not run, it "ends unexpectedly" but I just figured that this is normal for plugins (that they can't run for themselves and have to be integrated in another project) - is this right, or is something fundamental wrong with my plugin? I am seriously confused now, since every tutorial I looked up showed somewhat different things, right now I think I am running in circles, so, where did I do wrong?
(Sorry for so much code, but I don't really know where it could have broken, since I don't think that the problem lies within the "ui_itemview.h" file)
Headers:
itemview.h
#include "iteminformation.h"
using namespace std;
namespace Ui {
class ItemView;
}
class QDESIGNER_WIDGET_EXPORT ItemView : public QWidget
{
Q_OBJECT
itemInformation item;
QImage itemIcon;
string iconPath;
Q_PROPERTY(itemInformation item READ getItem WRITE setItem)
Q_PROPERTY(QImage itemIcon READ getIcon)
Q_PROPERTY(string iconPath READ getIconPath WRITE setIconPath)
itemInformation getItem () const;
void setItem (itemInformation item_);
QImage getIcon () const;
string getIconPath () const;
void setIconPath (string path);
public:
explicit ItemView(QWidget *parent = 0);
~ItemView();
int heightForWidth(int width) const;
QSize sizeHint() const;
QSize minimumSizeHint() const;
private:
Ui::ItemView *ui;
};
#endif // ITEMVIEW_H
itemviewplugin.h
#ifndef ITEMVIEWPLUGIN_H
#define ITEMVIEWPLUGIN_H
#include <QIcon>
#include <QObject>
#include <QtUiPlugin/customwidget.h>
class itemViewPlugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
Q_PLUGIN_METADATA(IID "com.ics.Qt.CustomWidgets.PenAndPaper.ItemView")
#endif
public:
explicit itemViewPlugin(QObject *parent = 0);
QString name() const;
QString group() const;
QString toolTip() const;
QString whatsThis() const;
QString includeFile() const;
QIcon icon() const;
bool isContainer() const;
QWidget *createWidget(QWidget *parent);
private:
bool initialized;
signals:
public slots:
};
#endif // ITEMVIEWPLUGIN_H
ui_itemview.h - the ominous file all the errors come from (I didn't include the complete file, just the "wrong" parts, since it's rather long; There are more QStringLiterals in the file, but one should suffice ;) )
#ifndef UI_ITEMVIEW_H
#define UI_ITEMVIEW_H
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QFrame>
#include <QtWidgets/QGraphicsView>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLabel>
#include <QtWidgets/QStackedWidget>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_ItemView
{
if (ItemView->objectName().isEmpty())
ItemView->setObjectName(QStringLiteral("ItemView"));
ItemView->resize(512, 84);
...
}
Sources:
itemview.cpp
#include "itemview.h"
#include "ui_itemview.h"
ItemView::ItemView(QWidget *parent) :
QWidget(parent),
ui(new Ui::ItemView)
{
ui->setupUi(this);
ui->nameOut->setText("<p><strong><span style=\"font-size:16px;\">###Name###</span></strong></p>");
ui->nameOut->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
}
ItemView::~ItemView()
{
delete ui;
}
//heightForWidth, sizeHint, minimumSizeHint functions skipped for better readability
itemInformation ItemView::getItem() const {
return item;
}
void ItemView::setItem(itemInformation item_) {
item = item_;
update();
}
QImage ItemView::getIcon() const {
return itemIcon;
}
string ItemView::getIconPath() const {
return iconPath;
}
void ItemView::setIconPath(string path) {
iconPath = path;
update();
}
itemviewplugin.cpp
#include "itemviewplugin.h"
#include "itemview.h"
itemViewPlugin::itemViewPlugin(QObject *parent) :
QObject(parent),
initialized(false)
{
}
//name, group, toolTip, whatsThis and includeFile functions skipped
QIcon itemViewPlugin::icon() const {
return QIcon();
}
bool itemViewPlugin::isContainer() const {
return false;
}
QWidget * itemViewPlugin::createWidget(QWidget *parent) {
return new ItemView(parent);
}
Project files
.pro file of plugin
QT += core gui
CONFIG += debug
greaterThan(QT_MAJOR_VERSION, 4) {
QT += widgets designer
CONFIG += plugins release
}
CONFIG += c++11
QMAKE_CXXFLAGS += -std=c++11
TEMPLATE = lib
TARGET = $$qtLibraryTarget($$TARGET)
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
INCLUDEPATH += .
SOURCES += main.cpp\
.
.
.
itemviewplugin.cpp
HEADERS += itemview.h \
.
.
.
itemviewplugin.h
FORMS += itemview.ui
.pro file of the project I included the plugin in
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
QMAKE_CXXFLAGS += -std=c++11
TARGET = PenAndPaperGameHelper
TEMPLATE = app
SOURCES += main.cpp\
.
.
.
itemview.cpp \
itemviewplugin.cpp
HEADERS += penandpaper.h \
.
.
.
itemview.h \
itemviewplugin.h
FORMS += mainwindow.ui \
loadingscreen.ui \
(Note: I've only included the plugin-specific files, the whole plugin uses several of my own classes, if it is needed for debugging, I can post them as well, but this shouldn't be the problem)
Aucun commentaire:
Enregistrer un commentaire