I want a custom window frame for an app I've made in Qt 5.4 with QML.Before implementing it on my main project, I tried the following on a default application:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
//QQmlApplicationEngine engine;
//engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QDeclarativeView view;
viewsetWindowFlags(Qt::FramelessWindowHint
| Qt::WindowSystemMenuHint
| Qt::WindowMinimizeButtonHint
| Qt::Window);
view.setAttribute(Qt::WA_TranslucentBackground);
view.setMaximumHeight(640);
view.setMaximumWidth(350);
view.viewport()->setAutoFillBackground(false);
view.show();
return app.exec();
}
Here is the .pro file:
TEMPLATE = app
QT += qml quick widgets
QT += core gui widgets quick
QT += network
SOURCES += main.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)
The errors:
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QDeclarativeDebuggingEnabler::QDeclarativeDebuggingEnabler(void)" (__imp_??0QDeclarativeDebuggingEnabler##QEAA#XZ) referenced in function "void __cdecl `dynamic initializer for 'qmlEnableDebuggingHelper''(void)" (??__EqmlEnableDebuggingHelper##YAXXZ)
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QDeclarativeView::QDeclarativeView(class QWidget *)" (__imp_??0QDeclarativeView##QEAA#PEAVQWidget###Z) referenced in function main
main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl QDeclarativeView::~QDeclarativeView(void)" (__imp_??1QDeclarativeView##UEAA#XZ) referenced in function main
I know this is related to my .pro file but not too good in understanding LNk errors, I've tried different things but no progress, till now. How to fix this?
Add to the pro file:
QT += declarative
From the doc:
For the purposes of porting older applications, the QtDeclarative
module is still available in Qt 5 but has been renamed to Qt Quick 1.
Applications that required Qt Quick 1 specific API (e.g.
QDeclarativeView or QDeclarativeItem and the Graphics View
integration) can use this module. Note that new applications should
use the new Qt QML and Qt Quick modules instead.
To use the Qt Quick 1 module, add "declarative" to your qmake .pro
file:
Required header files can be included as follows:
#include <QtDeclarative/QDeclarativeView>
#include <QtDeclarative/QDeclarativeItem>
Also:
All classes that were previously in the QtDeclarative module have been
moved into the Qt QML and Qt Quick modules, and their class names have
been changed to reflect their new module locations. The class name
changes are as follows:
... QDeclarativeView -> QQuickView
But:
(The QtDeclarative module is still available to developers as the Qt
Quick 1 module, as discussed below. However, it should not be used for
new applications.)
Related
I'm trying to create a OpenGL widget using Qt 6.4 and VStudio 2022, i have enable the Qt OpenGL widget under the modules, but i still getting a lot of compile errors:
LNK2019 unresolved external symbol "__declspec(dllimport) public: __cdecl QOpenGLWidget::QOpenGLWidget(class QWidget *,class QFlags<enum Qt::WindowType>)" (__imp_??0QOpenGLWidget##QEAA#PEAVQWidget##V?$QFlags#W4WindowType#Qt#####Z) referenced in function "public: void __cdecl Ui_MainWindowClass::setupUi(class QMainWindow *)" (?setupUi#Ui_MainWindowClass##QEAAXPEAVQMainWindow###Z)
I'm testing in a 'clean' project containing nothing more than a OpenGlWidget added trough QT Designer.
The includes i have added:
#include <QtWidgets>
#include <QtOpenGL>
My project configuration:
I have also tried adding, into Linker -> General -> Additional Library directories:
D:\Qt\6.4.0\msvc2019_64\lib;
And at Linker -> Input -> Additional Dependencies:
Qt6OpenGL.lib
But i continue getting the same errors.
I have installed everything in the Qt Maintenance tool, what i'm missing?
QOpenGLWidget has been moved to Qt OpenGL Widgets module.
You must to link against both Qt6OpenGL.lib and Qt6OpenGLWidget.lib.
https://doc.qt.io/qt-6/opengl-changes-qt6.html#the-qopenglwidgets-class
Which help from Qt Forum, I found that these errors were being caused because I was missing adding the openglwidgets module into the project.
After setting Qt Modules to core;gui;widgets;opengl;openglwidgets it compiled successfully.
It strange that the module openglwidgets is missing in the plugin window of Qt Modules, should be reported as a bug/missing?
I'm foraying into C++ and QT 5.9.
I'm running QT Tools for VS 2017 with QT 5.9 libraries added to VS 2017 and am building QT GUI applications without issue.
However, when I try to build a very simple example that invloves QWebEngineView or QWebEnginePage, I'm geting unresolved external symbol "__declspec(dllimport)...on QWebEngineView...
I've also noticed that a few of the #includes don't match the examples on the QT 5.9 doc site...
I've uninstalled and re-installed QT 5.9 and also 5.6 a few times and included every module I could into each, just in case!
Code
#include <QtWidgets/QtWidgets>
#include <QtWidgets/QApplication>
#include <QtWebEngineWidgets/QtWebEngineWidgets>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWebEngineView view;
view.show();
view.load(QUrl("http://google.com"));
return a.exec();
}
Build Output
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QWebEngineView::QWebEngineView(class QWidget *)" (__imp_??0QWebEngineView##QEAA#PEAVQWidget###Z) referenced in function main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl QWebEngineView::~QWebEngineView(void)" (__imp_??1QWebEngineView##UEAA#XZ) referenced in function main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl QWebEngineView::load(class QUrl const &)" (__imp_?load#QWebEngineView##QEAAXAEBVQUrl###Z) referenced in function main
You need to add the QtWebEngine library to the linker. Open the qmake .pro file and add QT += webenginewidgets. http://doc.qt.io/qt-5/qwebengineview.html
I'm trying to compile a qt project (within Qt Creator 2.7.0 on Qt 5.0.2) and I keep getting linker errors that have to do with the QtSQL library (KioskBridge is the file/class that I am using sql in):
kioskbridge.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QSqlDatabase::QSqlDatabase(void)" (__imp_??0QSqlDatabase##QEAA#XZ) referenced in function "public: __cdecl KioskBridge::KioskBridge(class Html5ApplicationViewer *)" (??0KioskBridge##QEAA#PEAVHtml5ApplicationViewer###Z)
My pro file includes QT += sql, but that doesn't seem to make it link with the appropriate libraries.
Any ideas?
After you modify the .pro file you will need to run qmake (that will re-generate the makefiles with the right dependencies) and only after that you can successfully link your application with the newly added modules.
I am trying to make a very simple GUI application, on the top of some C++ code which I wrote. My problem could be simplifed to the following:
#include <QtGui\QDialog>
void setup(int argc, char **argv) {
QDialog dlg;
}
int main(int argc, char **argv) {
setup(argc, argv);
}
I configured my Qt library, and I am pretty sure that the libraries are compatible with my Visual Studio 2010 (other projects worked fine), but I don't know if I should create a header file. I am always receiving these errors:
>main.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall QDialog::~QDialog(void)" (??1QDialog##UAE#XZ)
1>main.obj : error LNK2001: unresolved external symbol "public: __thiscall QDialog::QDialog(class QWid.................
The errors you got signals that VS compiler cannot determine addresses of invocation the external functions you've used, namely ctor and dtor for QDialog class object. To avoid such errors you should specify the location of the libraries containing the definitions of that functions. In order to achieve this you should use "Project Properties"->"Configuration Properties"->"Linker"->"Input", then in the "Additional Dependencies" line input the absolute path to the external libs (e.g. "C:\Qt\4.8.3\lib\QtGui.lib").I suppose if you only got that errors you mentioned you set your include paths correctly. So specifying input libraries should help.For the future I'd suggest you install Qt VS Add-in. It adds some options to an ordinary VS "Create new project" dialog, so you can choose "New Qt project" and all the required paths will be set automatically.
sys info : win xp SP3 , Microsoft Visual Studio 2008
Version 9.0.21022.8 RTM
Microsoft .NET Framework
Version 3.5 SP1
Qt Add-in 1.1.5
I installed Qt 4.6.3 from the site http://qt.nokia.com/downloads/windows-cpp-vs2008.
Then I added the Add-in Qt 1.1.5 and configured the PATH variable.
When I open a new QT project , default example works just fine.
On Nokia (qt) site I found some examples but it seems that things are not working properly.
Here is one of many examples that do not work :
#include <QtGui>
#include <QWidget>
class QLabel;
class QLineEdit;
class QTextEdit;
class AddressBook : public QWidget
{
Q_OBJECT
public:
AddressBook(QWidget *parent = 0);
private:
QLineEdit *nameLine;
QTextEdit *addressText;
};
AddressBook::AddressBook(QWidget *parent)
: QWidget(parent)
{
QLabel *nameLabel = new QLabel(tr("Name:"));
nameLine = new QLineEdit;
QLabel *addressLabel = new QLabel(tr("Address:"));
addressText = new QTextEdit;
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(nameLabel, 0, 0);
mainLayout->addWidget(nameLine, 0, 1);
mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
mainLayout->addWidget(addressText, 1, 1);
setLayout(mainLayout);
setWindowTitle(tr("Simple Address Book"));
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
AddressBook addressBook;
addressBook.show();
return app.exec();
}
Compiler says this ::
Output Window
Linking...
main.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall AddressBook::metaObject(void)const " (?metaObject#AddressBook##UBEPBUQMetaObject##XZ)
main.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall AddressBook::qt_metacast(char const *)" (?qt_metacast#AddressBook##UAEPAXPBD#Z)
main.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall AddressBook::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall#AddressBook##UAEHW4Call#QMetaObject##HPAPAX#Z)
main.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const AddressBook::staticMetaObject" (?staticMetaObject#AddressBook##2UQMetaObject##B)
C:\Documents and Settings\nik\My Documents\Visual Studio 2008\Projects\vs_03\Debug\vs_03.exe : fatal error LNK1120: 4 unresolved externals
Results
Build log was saved at "file://c:\Documents and Settings\nik\My Documents\Visual Studio 2008\Projects\vs_03\vs_03\Debug\BuildLog.htm"
vs_03 - 5 error(s), 0 warning(s)
It seems to me that the thing has to do with the use of macro Q_OBJECT but just dont know what to do that thing starts to work properly.
Maybe wrong installation or ... NO IDEA
Any help is appreciated.
I don't think it's a wrong installation - I assume you're using Visual Studio to build the project and in that case, you also need to tell it to build the _moc.cpp files that should have been generated for your class AddressBook.
If they haven't been generated you also need to run moc on the header files for AddressBook.
Any time you need moc to run against your files and you don't have your class in a separate header and implementation file you need to have a #include "FILENAME.moc" at the end of your file. If you were to add that after your main function, everything should work.
You should be able to test this by going into your project directory and doing the following:
Delete any makefiles that may be present
Run the Visual Studio Command Prompt
Run qmake -project to generate a project file
Run qmake to generate the makefiles
Run nmake to build the project
The nmake command should completely successfully and without linking errors on a simple project like the above. For more complex projects, you might need to modify the .pro file to include Qt`s webkit or otherwise make accessible options which are not available by default.
The alternative is to move the class definition for AddressBook into a header file with an appropriate implementation (cpp/cxx) file.
I find solution.
Read all the details about the installation on this page >>
http://dcsoft.wordpress.com/?aspxerrorpath=/community_server/blogs/dcsoft/archive/2009/03/06/how-to-setup-qt-4-5-visual-studio-integration.aspx.
After a whole day of studying and configuration, I finally managed to enable QT 4.6.3. on the VS 2008. Follow the detailed instructions and there should not be a problem.
My problem was that I used the following options:
Starting with Qt 4.6, the LPGL version now comes pre-built for Visual Studio 2008 RTM. If this fits your need, you can simply install it and skip to INSTALL VISUAL STUDIO ADD-IN.
This was wrong in my case so I go to next chapter :
DOWNLOAD QT SOURCE CODE
As the option to download only the Qt source code is a bit obfuscated on the current Nokia website, please follow these directions: ................................................................................................................................................................................................................................. etc. READ ON THE SITE.
For now all works great.There are no errors in linking. MOC works fine ...