February 20, 2012

Alastor Alastor
Lab Rat
2 posts

[Solved]Problem QT heritage : Can’t compile a basic code

 

Hey all,
I just started to use QT 4.8 and I have a problem when I would make a heritage class.
I use Visual C++ 2010, I have configure my IDE and when I compile a basic appli, it works.
But when I tried to use heritage..

My source :
main.cpp

  1. #include "ONavMain.h"
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5.  QApplication app(argc, argv);
  6.  
  7.  ONavMain appli;
  8.  appli.show();
  9.  
  10.  return app.exec();
  11. }

ONavMain.h

  1. #ifndef ONAVMAIN_H
  2. #define ONAVMAIN_H
  3.  
  4. #include <QtGui/qapplication.h>
  5. #include <QtGui/qtgui>
  6.  
  7. class ONavMain : public QWidget
  8. {
  9. public:
  10.  ONavMain();
  11.  virtual ~ONavMain();
  12.  
  13. protected:
  14.  
  15. private:
  16.  QPushButton *mBouton;
  17.  
  18. };
  19.  
  20. #endif

ONavMain.cpp

  1. #include "ONavMain.h"
  2.  
  3. ONavMain::ONavMain() : QWidget()
  4. {
  5.     setFixedSize(1024, 768);
  6.  
  7.     mBouton = new QPushButton("", this);
  8.  
  9.  mBouton->setFont(QFont("Arial"));
  10.  mBouton->setText("Bouton");
  11.  mBouton->setToolTip("Tooltip de Bouton");
  12.  mBouton->move(10, 5);
  13. }
  14.  
  15. ONavMain::~ONavMain()
  16. {
  17.  delete mBouton;
  18.  mBouton = NULL;
  19. }

And the compile error is :

  1. La génération a démarré 20/02/2012 03:30:37.
  2.      1>Projet "C:\Users\Alastor\documents\visual studio 2010\Projects\Projects\Projects\Projects.vcxproj" sur le nœud 2 (build cible(s)).
  3.      1>Build:
  4.          qmake & nmake
  5.          
  6.          Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
  7.          Copyright (C) Microsoft Corporation. Tous droits rÚservÚs.
  8.          
  9.           "C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\nmake.exe" -f Makefile.Debug
  10.          
  11.          Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
  12.          Copyright (C) Microsoft Corporation. Tous droits rÚservÚs.
  13.          
  14.           cl -c -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"c:\Qt\4.8.0\include\QtCore" -I"c:\Qt\4.8.0\include\QtGui" -I"c:\Qt\4.8.0\include" -I"." -I"c:\Qt\4.8.0\include\ActiveQt" -I"debug" -I"c:\Qt\4.8.0\mkspecs\win32-msvc2010" -Fodebug\ @C:\Users\Alastor\AppData\Local\Temp\nmC865.tmp
  15.          main.cpp
  16.      1>.\main.cpp(11): error C2039: 'show' : n'est pas membre de 'QApplication'
  17.                 c:\qt\4.8.0\include\qtgui\../../src/gui/kernel/qapplication.h(97) : voir la déclaration de 'QApplication'
  18.     1>NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\cl.EXE"'á: code retour '0x2'
  19.         Stop.
  20.     1>NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\nmake.exe"'á: code retour '0x2'
  21.         Stop.
  22.     1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073: La commande "qmake & nmake" s'est arrêtée avec le code 2.
  23.      1>Génération du projet "C:\Users\Alastor\documents\visual studio 2010\Projects\Projects\Projects\Projects.vcxproj" terminée (build cible(s)) -- ÉCHEC.
  24.  
  25. ÉCHEC de la build.
  26.  
  27. Temps écoulé 00:00:06.13

I hope that someone can help me.
Thanks for read, and please, excuse me for my poor english, I’m french.

3 replies

February 20, 2012

Lukas Geyer Lukas Geyer
Lab Rat
2074 posts

Well, your compiler output doesn’t match the sources you’ve listed. Are you sure you are building the current project or is there any old code that might be opened as well and is built instead?

Two annotations:

  • All QObject derived classes should have a default constructur having a parent parameter
    1. ONavMain(QObject *parent = 0);
    resp.
    1. ONavMain::ONavMain(QObject *parent) : QWidget(parent)
  • You should use layouts instead of fixed positioning

February 20, 2012

Alastor Alastor
Lab Rat
2 posts

Hum,

Thank you for your answer :
bq. Are you sure you are building the current project

I have regenerate my projetc and it’s working.

I really look stupid ..

February 20, 2012

Lukas Geyer Lukas Geyer
Lab Rat
2074 posts

Alastor wrote:
Thank you for your answer.
I have regenerate my projetc and it’s working.

You’re welcome.

Alastor wrote:

I really look stupid ..

Nope. Such things just happen – to all of us.

 
  ‹‹ Memory Leak tools for Windows-7 (64-bit) & VC++ 2008 ???      [SOLVED]iomanip in Qt: Manipulating displayed text ››

You must log in to post a reply. Not a member yet? Register here!