I'm trying to build a small Qt6 application on a Docker container. It is running on Ubuntu:22.04. I have installed the qt6-base-dev package. Here is my small test app:
#include <QApplication>
#include <QWidget>
#include <iostream>
int main(int argc, char argv)
{
QApplication app(argc, argv);
QWidget widget;
widget.setFixedSize(400, 400);
QString helloString = "Hello from " + qgetenv("USER") + "!";
widget.setWindowTitle(helloString);
widget.show();
return QApplication::exec();
}
And here is my CMakeList.txt:
cmake_minimum_required(VERSION 3.0)
project(testproj)
find_package(Qt6 REQUIRED COMPONENTS Widgets)
add_executable(testproj main.cpp)
target_link_libraries(testproj PRIVATE Qt6::Widgets)
But when my cmake is configuring this error appear:
CMake Error at CMakeLists.txt:5 (find_package):
Found package configuration file:
/usr/lib/x86_64-linux-gnu/cmake/Qt6/Qt6Config.cmake
but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT
FOUND. Reason given by package:
Failed to find Qt component "Widgets".
Expected Config file at
"/usr/lib/x86_64-linux-gnu/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake" exists
The /usr/lib/x86_64-linux-gnu/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake is existing.
I couldn't find anything online about this problem.
I have installed libgl1-mesa-dev and libglvnd-dev and it worked perfectly !
Related
Why is QPdfDocument not found?
During installation I selected Additional Libraries "Qt PDF" and "Qt WebEngine". Then I wrote this code in CMake:
find_package(Qt6 REQUIRED COMPONENTS Pdf)
target_link_libraries(mytarget Qt6::Pdf)
Then I got the message:
"Found package configuration file: C:/Qt/6.3.1/mingw_64/lib/cmake/Qt6/Qt6Config.cmake but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT FOUND. Reason given by package: Failed to find Qt component "Pdf". Expected Config file at "C:/Qt/6.3.1/mingw_64/lib/cmake/Qt6Pdf/Qt6PdfConfig.cmake" does NOT exist"
#include <QApplication>
#include <QPdfDocument> //not found
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Dont know the qt version. Community Edition? Maybe this helps:
QtPDF Build Instructions
I am following this qt tutorial.
helloworld.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = helloworld
TEMPLATE = app
SOURCES += main.cpp
main.cpp
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPushButton button ("Hello world!");
button.show();
return a.exec(); // .exec starts QApplication and related GUI, this line starts 'event loop'
}
Type the following shell commands to build the program.
qmake -project
Error:
PS E:\QT_tut\Tut_cmake_1\nSR> qmake -project
Project ERROR: Cannot run compiler 'cl'. Output:
===================
===================
Maybe you forgot to setup the environment?
PS E:\QT_tut\Tut_cmake_1\nSR>
QT: 5.12.12
VS: 2019
But, I can run this program using QT GUI.
I have problems loading the built-in plugins for iconengines for a deployed application. Below is a minimal program to show the problem. It is not exactly the same, because Qt scans the plugin directories at start and registers it according to the file suffix, but I hope when I can get the minimal program to run, then the automatic scanning works, too.
main.cpp:
#include <QCoreApplication>
#include <QPluginLoader>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QPluginLoader loader("C:/Qt/5.15.1/msvc2019_64/plugins/iconengines/qsvgicon.dll");
if (loader.load()) {
qDebug() << "load ok";
} else {
qDebug() << "load failed";
}
return a.exec();
}
and PluginTest.pro:
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
SOURCES += main.cpp
When I start it from the Qt Creator IDE, version 4.13.1, with Visual Studio 2019, 64 bit compiled, it prints "load ok". Now I do this from a "x64 Native Tools Command Prompt for VS 2019" command prompt in the project directory:
set PATH=%PATH%;C:\Qt\5.15.1\msvc2019_64\bin
mkdir deploy
copy release\PluginTest.exe deploy
windeployqt --release release\PluginTest.exe --plugindir deploy\QtPlugins
When I start PluginText.exe from the command prompt in the deploy directory, I get the output "load failed".
Additional information: when I set set qt_debug_plugins=1 and start the real application, I see these errors:
QFactoryLoader::QFactoryLoader() checking directory path "C:/projects/deploy/QtPlugins/iconengines" ...
QFactoryLoader::QFactoryLoader() looking at "C:/projects/deploy/QtPlugins/iconengines/qsvgicon.dll"
"Failed to extract plugin meta data from 'C:/projects/deploy/QtPlugins/iconengines/qsvgicon.dll'"
not a plugin
The qsvgicon.dll file is identical to "c:\Qt\5.15.1\msvc2019_64\plugins\iconengines\qsvgicon.dll".
I found the problem. It used some other Qt DLLs from the path when starting the application. This fixed it:
xcopy /y c:\Qt\5.15.1\msvc2019_64\bin\*.dll deploy
I have made a small QT application and i am trying to run it thru command prompt on Windows:
#include <QMainWindow>
#include <QLabel>
int main(int argc,char* argv[])
{
QMainWindow a(argc,argv)
QLabel *NewLabel = new QLabel("Hi i am a label");
NewLabel->show();
return a.exec();
}
after doing qmake -project
and then qmake -TestPrg.pro
then i try make,here it fails with following error:
D:\TestPrg>make
make -f Makefile.Debug
make[1]: Entering directory `D:/TestPrg'
Makefile.Debug:58: *** missing separator. Stop.
make[1]: Leaving directory `D:/TestPrg'
make: *** [debug] Error 2
If we look at makefile.debug ,line number 58 and add a TAB before "<<",it complains at someother line number.So i feel there is something wrong in the compiler options ,can someone guide how to make it working.
Thanks alot
I have just made an example work on my machine. The code goes below, but you have at least a few mistakes, namely:
You use QMainWindow for being the application as it seems as opposed to QApplication. That is not going to compile.
Respectively, you would need to include QApplication rather than QMainWindow.
You miss a semi-colon after the first statement in the main function.
You construct a QLabel on the heap needlessly. In this particular scenario, it could be a simple stack object.
You use invoking qmake as qmake -foo rather than just qmake or make foo.
You are trying to use "make" in the Windows Command prompt as opposed to nmake or jom. If you use Visual Studio and MSVC, do not mix it with mingw, cygwin and other things. Just use nmake, otherwise, yes, use make for the latter options.
main.cpp
#include <QApplication>
#include <QLabel>
int main(int argc, char **argv)
{
QApplication a(argc, argv);
QLabel NewLabel("Hi i am a label");
NewLabel.show();
return a.exec();
}
main.pro
TEMPLATE = app
TARGET = main
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += main.cpp
Build and Run
* qmake
* nmake
* main.exe
I want to embedded python code in Qt C++ code. I create a console Qt app for test.
My .pro is
SOURCES += main.cpp
LIBS = -lboost_python -lpython27
HEADERS += /usr/include/python2.7
My main.cpp file is
#include <QCoreApplication>
#include <boost/python.hpp>
using namespace boost::python;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
return a.exec();
}
But I found I can't build this program.
error message is:
/usr/include/boost/python/detail/wrap_python.hpp:50:
Error:pyconfig.h: No such file or directory
I googled this problem, but havn't got answer.
How to configure Qt I want embedded Python code in My Qt C++ program?
it's INCLUDEPATH, not HEADERS in .pro file.
You must install python developer package at first.
In Ubuntu you can use apt-get as the following:
apt-get install python2.7-dev