July 12, 2010

doforumda doforumda
Lab Rat
161 posts

Create window help

 

i am trying another example and something weird is going on here
this is my example in main.cpp

  1. #include <QtGui>  
  2.  
  3. int main(int argc, char *argv[])
  4.  {
  5.      QApplication app(argc, argv);
  6.      QWidget window;
  7.      window.resize(320, 240);
  8.      window.setWindowTitle(QApplication::translate("childwidget", "Child widget"));
  9.      window.show();
  10.       QPushButton *button = new QPushButton(
  11.          QApplication::translate("childwidget", "Press me"), &window);
  12.      button->move(100, 100);
  13.      button->show();
  14.      return app.exec(&#41;;
  15.  }

mainwindow.cpp

  1. #include "mainwindow.h"
  2.  
  3. #include "ui_mainwindow.h"
  4.   MainWindow::MainWindow(QWidget *parent) :
  5.      QMainWindow(parent),
  6.      ui(new Ui::MainWindow)
  7.  {
  8.      ui->setupUi(this);
  9.  }
  10.   MainWindow::~MainWindow()
  11.  {
  12.      delete ui;
  13.  }

mainwindow.h

  1. #ifndef MAINWINDOW_H
  2.  
  3. #define MAINWINDOW_H
  4.   #include <QMainWindow>
  5.   namespace Ui {
  6.      class MainWindow;
  7.  }
  8.   class MainWindow : public QMainWindow
  9.  {
  10.      Q_OBJECT
  11.   public:
  12.      explicit MainWindow(QWidget *parent = 0);
  13.      ~MainWindow();
  14.   private:
  15.      Ui::MainWindow *ui;
  16.  };
  17.   #endif // MAINWINDOW_H

when i run above code it works perfectly but when i change this line

  1. QPushButton *button = new QPushButton(QApplication::translate("childwidget", "Press me"), &window);

to

  1. QPushButton *button = new QPushButton(QApplication::translate("childwidget", "ok"), &window);

this it fails to run. then when i change it again to “Press me” again displays the error. it only runs when i open new file and create it from start and run it again then it works but it creates problem when i modify there.

here is the error in build issues tab

  1. :: error: [debug\ChildWindow2.exe] Error 1

this is in compile output tab

  1. Running build steps for project ChildWindow2...
  2. Configuration unchanged, skipping qmake step.
  3. Starting: "C:/Qt/2010.04/mingw/bin/mingw32-make.exe" -w
  4. mingw32-make: Entering directory `C:/Qt/2010.04/examples/ChildWindow2-build-desktop'
  5. C:/Qt/2010.04/mingw/bin/mingw32-make -f Makefile.Debug
  6. mingw32-make[1]: Entering directory `C:/Qt/2010.04/examples/ChildWindow2-build-desktop'
  7. g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\qt\include\QtCore" -I"..\..\qt\include\QtGui" -I"..\..\qt\include" -I"..\..\qt\include\ActiveQt" -I"debug" -I"." -I"..\ChildWindow2" -I"." -I"..\..\qt\mkspecs\win32-g++" -o debug\main.o ..\ChildWindow2\main.cpp
  8. g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\ChildWindow2.exe debug/main.o debug/mainwindow.o debug/moc_mainwindow.o -L"c:\Qt\2010.04\qt\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
  9. mingw32-make[1]: Leaving directory `C:/Qt/2010.04/examples/ChildWindow2-build-desktop'
  10. mingw32-make: Leaving directory `C:/Qt/2010.04/examples/ChildWindow2-build-desktop'
  11. mingw32-make[1]: *** [debug\ChildWindow2.exe] Error 1
  12. mingw32-make: *** [debug] Error 2
  13. The process "C:/Qt/2010.04/mingw/bin/mingw32-make.exe" exited with code %2.
  14. Error while building project ChildWindow2 (target: Desktop)
  15. When executing build step 'Make'

6 replies

July 12, 2010

Tobias Hunger Tobias Hunger
Hobby Entomologist
3373 posts

You did put preprocessor commands and code into the same line again:-)

See here [developer.qt.nokia.com] for why that does not work.

July 12, 2010

doforumda doforumda
Lab Rat
161 posts

it is not an issue because i put preprocessor commands and code on different line. It changed when i copy and paste it here. it is not an issue. problem is somewhere else.

and also why my Qt creator does not display exact errors. e.g, when i write C++ code or other language code in their respective IDEs and when i make mistakes then it displays the exact errors filename line number etc. but Qt creator doesnt for me. What can be the problem?

July 12, 2010

Tobias Hunger Tobias Hunger
Hobby Entomologist
3373 posts

Well, Creator does display all the errors contained in your compile output… and (at least in the part you pasted here) there are none, except for the one that is in the build issues tab. Creator is no compiler, it can only work with what compiler and buildsystem provide!

It would be very useful, if you would not change the code when pasting it. Please make sure that the pasted code compiles (or displays exactly the same issue you are asking about) when asking questions. It is rather hard to guess at issues based on mangled code!

Anyway: Syntactically the code seems to be correct (otherwise you would have gcc errors in your compile output). That leaves your buildsystem: What is in your .pro-file? Make errors are often a sign for issues there.

July 12, 2010

doforumda doforumda
Lab Rat
161 posts

when i paste code and do not change it runs fine. but when i want to make change like above then it fails to run and displays all those things above. and then when i change it to original code again then it still does not work which for the first time it worked

July 12, 2010

Tobias Hunger Tobias Hunger
Hobby Entomologist
3373 posts

All the 01 lines in your pasted code are wrong (either several preprocessor commands on one line or preprocessor commands and code in one line), so you should have some trouble if that is really the code you are running. Try fixing that.

If your code is different from what you pasted then please paste the real code and include the .pro file.

July 12, 2010

doforumda doforumda
Lab Rat
161 posts

ok i edit all 01 lines and here is my .pro file

  1. #-------------------------------------------------
  2. #
  3. # Project created by QtCreator 2010-07-12T15:54:51
  4. #
  5. #-------------------------------------------------
  6.  
  7. QT       += core gui
  8.  
  9. TARGET = untitled3
  10. TEMPLATE = app
  11.  
  12.  
  13. SOURCES += main.cpp\
  14.         mainwindow.cpp
  15.  
  16. HEADERS  += mainwindow.h
  17.  
  18. FORMS    += mainwindow.ui

 
  ‹‹ Qt-Designer, which approach to ui-files do you use?      QMake and make with parallel jobs [bug?] ››

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