Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Save object to a file
Forum Updated to NodeBB v4.3 + New Features

Save object to a file

Scheduled Pinned Locked Moved General and Desktop
37 Posts 2 Posters 13.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #27

    Looks strange... Just to be on the safe side, delete the build directory completely and re-run your application.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dmon
      wrote on last edited by
      #28

      ok now it doesn't run again with a bunch of errors:

      Running build steps for project Ass1Q1...
      Configuration unchanged, skipping qmake step.
      Starting: "C:/Qt/2010.04/mingw/bin/mingw32-make.exe" -w
      mingw32-make: Entering directory C:/Unisa/COS3711/assignments/Ass1Q1-build-desktop' C:/Qt/2010.04/mingw/bin/mingw32-make -f Makefile.Debug mingw32-make[1]: Entering directory C:/Unisa/COS3711/assignments/Ass1Q1-build-desktop'
      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\2010.04\qt\include\QtCore" -I"........\Qt\2010.04\qt\include\QtGui" -I"........\Qt\2010.04\qt\include" -I"........\Qt\2010.04\qt\include\ActiveQt" -I"debug" -I"." -I"..\Ass1Q1" -I"." -I"........\Qt\2010.04\qt\mkspecs\win32-g++" -o debug\FilmWriter.o ..\Ass1Q1\FilmWriter.cpp
      ..\Ass1Q1\FilmWriter.cpp: In member function 'void FilmWriter::saveFilm(Film&)':
      ..\Ass1Q1\FilmWriter.cpp:10: error: no matching function for call to 'QFileDialog::getSaveFileName(FilmWriter* const, const char [10])'
      ........\Qt\2010.04\qt\include\QtGui/../../src/gui/dialogs/qfiledialog.h:216: note: candidates are: static QString QFileDialog::getSaveFileName(QWidget*, const QString&, const QString&, const QString&, QString*, QFlagsQFileDialog::Option)
      ..\Ass1Q1\FilmWriter.cpp:14: error: no matching function for call to 'QMessageBox::critical(FilmWriter* const, const char [6], const char [20])'
      ........\Qt\2010.04\qt\include\QtGui/../../src/gui/dialogs/qmessagebox.h:202: note: candidates are: static QMessageBox::StandardButton QMessageBox::critical(QWidget*, const QString&, const QString&, QFlagsQMessageBox::StandardButton, QMessageBox::StandardButton)
      ........\Qt\2010.04\qt\include\QtGui/../../src/gui/dialogs/qmessagebox.h:262: note: static int QMessageBox::critical(QWidget*, const QString&, const QString&, int, int, int)
      ........\Qt\2010.04\qt\include\QtGui/../../src/gui/dialogs/qmessagebox.h:265: note: static int QMessageBox::critical(QWidget*, const QString&, const QString&, const QString&, const QString&, const QString&, int, int)
      ........\Qt\2010.04\qt\include\QtGui/../../src/gui/dialogs/qmessagebox.h:272: note: static int QMessageBox::critical(QWidget*, const QString&, const QString&, QMessageBox::StandardButton, QMessageBox::StandardButton)
      mingw32-make[1]: Leaving directory C:/Unisa/COS3711/assignments/Ass1Q1-build-desktop' mingw32-make: Leaving directory C:/Unisa/COS3711/assignments/Ass1Q1-build-desktop'
      mingw32-make[1]: *** [debug/FilmWriter.o] Error 1
      mingw32-make: *** [debug] Error 2
      The process "C:/Qt/2010.04/mingw/bin/mingw32-make.exe" exited with code %2.
      Error while building project Ass1Q1 (target: Desktop)
      When executing build step 'Make'

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #29

        FilmWriter is not a QWidget, you can't pass it as a parent when you call QFileDialog::getSaveFileName

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Dmon
          wrote on last edited by
          #30

          If I make FilmWriter a QWidget the program runs but when I click on the save film button it crashes with: "this application has requested the runtime to terminate it in an unusual way. Please contact the application's support team for more information."

          Despite the crash, the program runs without any errors as you can see:
          Running build steps for project Ass1Q1...
          Configuration unchanged, skipping qmake step.
          Starting: "C:/Qt/2010.04/mingw/bin/mingw32-make.exe" -w
          mingw32-make: Entering directory C:/Unisa/COS3711/assignments/Ass1Q1-build-desktop' C:/Qt/2010.04/mingw/bin/mingw32-make -f Makefile.Debug mingw32-make[1]: Entering directory C:/Unisa/COS3711/assignments/Ass1Q1-build-desktop'
          mingw32-make[1]: Nothing to be done for first'. mingw32-make[1]: Leaving directory C:/Unisa/COS3711/assignments/Ass1Q1-build-desktop'
          mingw32-make: Leaving directory `C:/Unisa/COS3711/assignments/Ass1Q1-build-desktop'
          The process "C:/Qt/2010.04/mingw/bin/mingw32-make.exe" exited normally.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #31

            Because you don't initialize it properly.

            Don't make FilmWriter inherit QWidget and don't make it a parent of the QFileDialog, it doesn't make any sense.

            For your tests just call QFileDialog::getSaveFileName().

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Dmon
              wrote on last edited by
              #32

              ok now I'm confused!?! I am calling getSaveFileNAme

              void FilmWriter::saveFilm(Film& f){
              QString fileName = QFileDialog::getSaveFileName(this,("Save File"));
              if (fileName != "") {
              QFile file(fileName);
              if (!file.open(QIODevice::WriteOnly)) {
              QMessageBox::critical(this, ("Error"),("Could not open file"));// error message
              } else {
              QTextStream stream(&file);
              stream << f.toString();
              stream.flush();
              file.close();
              }
              }

              }

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #33

                change "this" by 0,

                FilmWriter is not a QWidget and should not be just for the purpose of giving QFileDialog::getSaveFileName a parent.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  Dmon
                  wrote on last edited by
                  #34

                  ca you give me the line QString fileName = QFileDialog::getSaveFileName();
                  because I don't know what's wrong here?

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #35

                    Just call

                    @
                    QString fileName = QFileDialog()::getSaveFileName(0, tr("Save File..."));
                    @

                    Please, check the documentation

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      Dmon
                      wrote on last edited by
                      #36

                      thank you very much I did try that but it also didn't work...Needed to change the 'this' for the QMessageBox also. Can I just ask why would pointing to this(itself) be the wrong thing to do?

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #37

                        Because FilmWriter is not a widget.

                        And while you where inheriting QWidget, you never initialized it properly

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved