Qmake, setting up environment - c++

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.

Related

Why is QPdfDocument not found?

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

QSound Unexpected null receiver while playing .wav files

I would like to play .wav samples of engine through out Qt creator. Of course the very first thought was on QSound class, but I did whatever was necessary to play it and it always shows me
QCoreApplication::postEvent: Unexpected null receiver
Which means that I entered wrong path for file, it seems simple but I have tried with absoulte paths and etc. Nothing new has happened.
Sourcecode and photos, I am trying it on windows but I would like to run it on Raspberry(fedora).
#include <QCoreApplication>
#include <QSound>
#include <iostream>
#include <QMediaPlayer>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSound let("music/letitplay.wav");
let.play();
/*QMediaPlayer * music = new QMediaPlayer();
music->setMedia(QUrl("qrc:/sounds/letitplay.wav"));
music->play();
*/
return 0;
}
Snippet from .pro
QT += core
QT -= gui
QT += multimedia
TARGET = silnik1
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
RESOURCES +=
Screen of path and file directory
QSound plays sounds asynchronously; you're going to need to start your QCoreApplication first so there's an event loop running.

Running a QT application from Command promt in WIndows

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

How to change console mode to gui mode in QtCreator?

I am trying to convert an application console mode to gui mode but the problem is the console window still appearing with main window.What i want is to hide console window as it dose in gui mode.
.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = cmd
TEMPLATE = app
CONFIG -= console
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
mainfile
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
In creator go in project under tab Run Settings uncheck Run in terminal. cmd window will not appear.

Compiler can't find ui_xyz.h file

I've install Netbeans 7.2 and Qt 5 on Windows7. Everything compiles fine.
But recently when I create a Qt form and try to use it in this way:
New Project > C/C++ Qt Application > Finish
Right click on new Qt project > New > Qt Form > Finish
After saving ui file in Designer
This error appears:
newForm.h:11:24: fatal error: ui_newForm.h: No such file or directory
The content of main.cpp is :
#include <QGuiApplication>
#include "newForm.h"
int main(int argc, char *argv[])
{
// initialize resources, if needed
// Q_INIT_RESOURCE(resfile);
QGuiApplication app(argc, argv);
// create and show your widgets here
return app.exec();
}
I tried to manually create ui_xwz.h file and add it to my project. But I want it work automatically as same as before. How can I solve it?
I have a ridiculous solution, Maybe we should report it as a bug to Netbeans or Qt.
Go and active QtSVG and QtXml modules of your project and rebuild it. I tested this way and the problem vanished.