0

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

László Papp
  • 51,870
  • 39
  • 111
  • 135
Metoo
  • 400
  • 1
  • 7
  • More likely it is there are multiple errors in the Makefile. Can you update with the makefile.debug and also what is the second error it throws? – Oliver Matthews Jan 10 '14 at 10:24
  • `qmake -TestPrg.pro` is wrong. Just use `qmake` or `qmake TestPrg.pro`. – László Papp Jan 10 '14 at 10:24
  • QMainWindow a(argc,argv) -> change it to QApplication a(argc, argv) – Wagmare Jan 10 '14 at 10:27
  • @Laslo typo mistake i used qmake TestPrg.pro only. – Metoo Jan 10 '14 at 11:01
  • ####### Implicit rules .SUFFIXES: .c .cpp .cc .cxx {.}.cpp{debug\}.obj:: $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug\ @<< $< << {.}.cc{debug\}.obj:: $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug\ @<< $< << {.}.cxx{debug\}.obj:: $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug\ @<< $< << {.}.c{debug\}.obj:: $(CC) -c $(CFLAGS) $(INCPATH) -Fodebug\ @<< $< << {.}.cpp{debug\}.obj:: $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug\ @<< $< << {.}.cc{debug\}.obj:: $(CXX) -c $(CXXFLAGS) $(INCPATH) -Fodebug\ @<< $< < – Metoo Jan 10 '14 at 11:02
  • @Wagmare:Even that didnt help – Metoo Jan 10 '14 at 11:05
  • Looks to me that you're mixing mingw-make and nmake. (Probably generating makefiles for nmake but executing mingw-make). Try `nmake` (in a VS prompt), or make sure that you're using a Qt build for mingw. – Frank Osterfeld Jan 10 '14 at 11:18

1 Answers1

2

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
László Papp
  • 51,870
  • 39
  • 111
  • 135
  • Thanks for your feedback,but here is what is used on my command prompt:D:\TestPrg>qmake -project D:\TestPrg>qmake TestPrg.pro 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 – Metoo Jan 10 '14 at 11:16
  • @user3156680: please try again with a clean environment. Also, you have not paid attention to the "nmake" note I wrote. – László Papp Jan 10 '14 at 11:19
  • i cannot use "nmake" ,'nmake' is not recognized as an internal or external command, operable program or batch file. – Metoo Jan 10 '14 at 11:26
  • @user3156680: you have not set up the path. You could run the Visual Studio prompt to get over this, but really: are you using MSVC or mingw? You have not made it clear yet... – László Papp Jan 10 '14 at 11:27
  • I am using MSVC and in the env variables i have QMAKESPEC as "win 32-msvc.net" .unfortunately if i try to use VS2010 commmand prompt instead of opening a command prompt window it opens this folder location"C:\Windows\System32",i have no idea why – Metoo Jan 10 '14 at 11:33
  • @user3156680: navigate to the proper location with the `cd` command. – László Papp Jan 10 '14 at 11:34
  • Can you please elaborate a bit more ...i am sorry but i am new to running a QT application from command prompt – Metoo Jan 10 '14 at 11:46
  • It has not much to do with Qt. Type `cd C:\Path\To\Your\Project and then run qmake and nmake in there in the Visual Studio prompt. – László Papp Jan 10 '14 at 11:48
  • D:\testPrg>qmake -project D:\testPrg>qmake testPrg.pro D:\testPrg>nmake Microsoft (R) Program Maintenance Utility Version 10.00.30319.01 Copyright (C) Microsoft Corporation. All rights reserved. NMAKE : fatal error U1065: invalid option '-' Stop. It didn't work – Metoo Jan 10 '14 at 12:10
  • You do not need qmake -project, just qmake, and use my project file. Also, http://www.mathworks.com/matlabcentral/answers/94786 Also, which Qt version have you downloaded? Please give me a link. – László Papp Jan 10 '14 at 12:14
  • I am using QT4.3.0 ..i dont have download link right now.But still the issue persists ,please help – Metoo Jan 13 '14 at 05:50
  • So finally some success,in my debug folder I am able to generate my .exe file.I agree with you that it is very ancient but the project i am working it has a lot of legacy code written in QT 4.3.0 ,so that's why I have to use the same . – Metoo Jan 13 '14 at 05:59
  • and the issue was related to MAKEFLAGS which was pointing to a Qnx directory.Thanks Laszlo – Metoo Jan 13 '14 at 06:01
  • Yes, I read posts about that the other day. I was going to suggest that once the mingw/msvc is fixed. Glad, it is working now. You are welcome. :) – László Papp Jan 13 '14 at 06:04