Ant
Ant

Reputation: 867

Why doesn't my Qt application present a GUI when executed?

I have been given a C++/C code with a .pro file to compile in Qt (it is a large, messy code, so I would like to use Qt and the .pro file provided).

The code is intended to generate a GUI. I can compile it in Qt without any errors (on both Mac OS X 10.7.5 and Mac OS X 10.8), and I see the executable. However, when I click on it, nothing happens. When I run it the usual way via the command line nothing happens. Here are the run commands I'm trying:

./calc.app/Contents/MacOS/calc

exec ./calc.app/Contents/MacOS/calc (this one results in the output: [Process completed]).

In the .pro file (below), I do not see anything that seems to indicate I want a GUI. However, I read at the Qt help site that the GUI module does not need to be specified in the .pro file because it is included automatically. Perhaps I am misunderstanding something?

Are the any issues with my .pro file?

TEMPLATE = app
LANGUAGE = C++
TARGET = calc
VERSION = 3.1.0

CONFIG -= qt
CONFIG += warn_on
CONFIG += debug
#CONFIG += windows
CONFIG += console

DEFINES += IPMGEMPLUGIN
DEFINES += NOPARTICLEARRAY

!win32 {
  DEFINES += __unix
}

GMS_CPP = ../GMS
GMS_H   = $$GMS_CPP

DEPENDPATH +=
DEPENDPATH += .
DEPENDPATH += $$GMS_H

INCLUDEPATH +=
INCLUDEPATH += .
INCLUDEPATH += $$GMS_H

QMAKE_LFLAGS +=
OBJECTS_DIR = obj

SOURCES      +=   main.cpp

include($$GMS_CPP/gms.pri)

Upvotes: 2

Views: 2480

Answers (2)

Shog9
Shog9

Reputation: 159590

I don't know anything about Qt, and of course none of us know anything about the specific application you're compiling - so the assistance I can give you may be woefully inaccurate.

However, this sticks out like a sore thumb:

#CONFIG += windows
CONFIG += console

A quick Google search indicates that Qt does indeed support console applications - that is, applications which do not create a GUI, but instead act as console / terminal / command-line tools. This appears to be the case with the one you're working with. Presuming the application even works, it likely expects input to be passed to it on the command line, and will produce output of some sort in response - but with this configuration, it will not create a GUI.

I recommend contacting the person who gave you this application for further support.

Upvotes: 5

cbh2000
cbh2000

Reputation: 2193

CONFIG -= qt basically means "The target is [not] a Qt application/library and [does not require] the Qt library and header files." You should delete that line. Source: http://qt-project.org/doc/qt-4.8/qmake-variable-reference.html#config

Also, it couldn't hurt to add QT += core gui. This is normally done for you automatically, but since you're having project file problems it couldn't hurt... Also, make sure your main.cpp's main method ends in return a.exec();, and that a is a QApplication instance (Qt 4.x) or a QGUIApplication instance (Qt 5.x). main.cpp should be a short function that creates the main widget or window, shows it, then starts the event loop.

If your project still doesn't work properly, I would highly recommend that you ditch the project file. In other words, I would download the OS X package for the Qt SDK, create a new project, then import your files into the new project. After that, I would pluck only the necessary lines from your old .pro file and put them in the new one until it works (specifically, I noticed you have some custom DEFINES += ...). However, all of this advice assumes the fault lies in the project file, not your code. ;-)

Upvotes: 1

Related Questions