Running a QT application from Command promt in WIndows - c++

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

Related

Qmake, setting up environment

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.

Invisible text in QTextEdit

I am learning Qt and running examples from Qt SDK 5.9.1. I run the code below and write inside QTextEdit but no text appears. Cursor moves as I write but no text is shown. Window title text is shown. I added addApplicationFont and setFont calls below I found from web to the sample but it didn't help.
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFontDatabase::addApplicationFont("://Ubuntu-R.ttf");
app.setFont(QFont("Ubuntu", 11, QFont::Normal, false));
QTextEdit textEdit;
textEdit.show();
return app.exec();
}
I am on Ubuntu 16.04 and run following commands on bash to make executable:
qmake -makefile
make
./part1
I want the app to use the default Ubuntu system font. I learned that Qt uses fontconfig for fonts but I don't know how to trace the issue.
Edit
I thought QFontDatabase::addApplicationFont("://Ubuntu-R.ttf") call referenced system font but instead it is referencing font app resource file. I don't have resource file so obviously it won't work.
.pro file is below(unmodified sample file):
QT += widgets
SOURCES = main.cpp
# install
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tutorials/gettingStarted/gsQt/part1
INSTALLS += target
I tried to get system font using QFontDatabase but it didn't work:
app.setFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
This doesn't do anything with any of enum values including QFontDatabase::GeneralFont
QFontDatabase database;
QStringList fam = database.families();
fam size is zero.
I will try to use embedded font next.
I don't know the exact reason of the problem but the reason was not configuring fontconfig dependency properly before building qt. I solved it by reconfiguring and recompiling qt again. You can find more details at qt forum.

C++ build error in Netbeans using MinGW and Qt

I have installed the MinGW compiler and I am attempting to run a C++ QT Application from within Netbeans.
As you can see from this screenshot, I have successfully set up the native build tools using Netbeans:
Unfortunately when attempting to run my program, I get the following error:
make.exe": /bin/sh: Command not found
make.exe": /bin/sh: Command not found
make.exe": *** [.validate-impl] Error 127
BUILD FAILED (exit value 2, total time: 303ms)
Just to be clear, I am not running a complicated program, in fact, I am just trying to execute a basic generated main file:
#include <QApplication>
int main(int argc, char *argv[]) {
// initialize resources, if needed
// Q_INIT_RESOURCE(resfile);
QApplication app(argc, argv);
// create and show your widgets here
return app.exec();
}
You can download my Makefile-Debug and Makefile-impl here: http://wikisend.com/download/467700/makefiles.zip
I would be extremely grateful for your help.

use Boost python in Qt creator

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

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.