Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. [Solved] Moc file that does not get created
Forum Updated to NodeBB v4.3 + New Features

[Solved] Moc file that does not get created

Scheduled Pinned Locked Moved Installation and Deployment
8 Posts 4 Posters 36.3k 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.
  • V Offline
    V Offline
    vgoudreault
    wrote on 17 Feb 2012, 14:19 last edited by
    #1

    This a bit baffling to a new comer such as myself.

    We have this fairly large application that relies on Qt for interfacing. The idea is to convert it to static for distribution (it seems some dll's conflic with those of other tools for a shared distribution).
    Compiling Qt (version 4.5.2 used) as static went OK, but now, when trying to build the complete tool itself (using MS Visual Studio 2005, on Windows XT) we have one of the file, internally captioned as having been generated by the User Interface Compiler (the header of the file in question PrintersDialog.cpp reads:

    @/****************************************************************************
    ** Form implementation generated from reading ui file 'printersdialog.ui'
    **
    ** Created: Tue Mar 4 14:37:34 2008
    ** by: The User Interface Compiler ($Id: qt/main.cpp 3.3.0b1 edited Nov 24 13:47 $)
    **
    ** WARNING! All changes made in this file will be lost!
    ****************************************************************************/@

    as can be seen, this file is already 4 year old, and there is little hope I can locate the person who triggered its generation)

    failing to generate, the seemingly required moc_PrintersDialog.cpp is missing.

    If one starts by building a shared version of the program, a rather tedious process since then a shared version of Qt needs to be brought on line, the moc file is created along with the other 12 that pop up; and if that moc file is then added to the source code for the static build -- which does generate those other 12 moc files -- then comppilation proceeds properly and we do get our executable.

    So, the question is:

    • what is preventing the moc_PrintersDialog.cpp file form being created, and what can we do to make sure it is generated when needed in a static build?

    Best regards

    CBVG

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on 17 Feb 2012, 16:27 last edited by
      #2

      That file is generated by moc, the meta object compiler, a tool bundled with Qt.

      You can call it on the command line manually:

      @
      moc -o moc_file.cpp file.h
      @

      Or put that somewhere into your VS project.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vgoudreault
        wrote on 17 Feb 2012, 16:50 last edited by
        #3

        I will sure give this a try, as soon as I figure where to add the instruction, so thanks.

        Still, that is a work around, and I wonder why "moc" does it for the other files and not that one when in static. Does this mean there must be some of those "moc" commands that are part of the VS project, one of which is controlled and inhibited by a variable that is related to the build being static?

        Regards

        CBVG

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on 17 Feb 2012, 16:59 last edited by
          #4

          Does the PrintersDialog.h header file have a Q_OBJECT macro in it?

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vgoudreault
            wrote on 17 Feb 2012, 18:04 last edited by
            #5

            That is the whole file here:

            @#ifndef PRINTERSDIALOG_H
            #define PRINTERSDIALOG_H

            #include <QObject>
            #include <qdialog.h>

            class Q3VBoxLayout;
            class Q3HBoxLayout;
            class QGridLayout;
            class QSpacerItem;
            class QPushButton;
            class Q3ListBox;
            class Q3ListBoxItem;
            class QPrinter;
            class QLineEdit;

            class CPrintersDialog : public QDialog
            {
            Q_OBJECT

            public:
            CPrintersDialog( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, Qt::WFlags fl = 0 );
            ~CPrintersDialog();
            void print();

            public slots:
            bool getSelectedPrinterName(QString& name) {name = selectedPrinter; return printerSelected;}

            protected:
            Q3HBoxLayout* layout5;
            QSpacerItem* spacer5;
            QPushButton* okButton;
            QPushButton* cancelButton;
            Q3ListBox* lstPrinters;
            QString selectedPrinter;
            bool printerSelected;

            protected slots:
            virtual void languageChange();
            virtual void printerClicked(Q3ListBoxItem* item);
            };

            #endif // PRINTERSDIALOG_H@

            CBVG

            1 Reply Last reply
            0
            • S Offline
              S Offline
              steno
              wrote on 17 Feb 2012, 20:59 last edited by
              #6

              If you want visual studio to handle it, right click on the header file in solution explorer and select properties. In the properties dialog select under Item Type, custom build tool. Then fill in the fields as required. In the command line part, you want something like what volker suggested.

              @"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles$(ConfigurationName)\moc_%(Filename).cpp "-I$(QTDIR)\include\QtGui"" @

              Or something like that but specific to your project.

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vgoudreault
                wrote on 20 Feb 2012, 15:46 last edited by
                #7

                Ah ha!

                Thanks to you people clues and pointers, I was able to track down something that was different in the way the build step was defined for the PrintersDialog.h file. Instead of having

                $(InputDir)moc_$(InputName).cpp

                for output as all the other header files associated with 'moc', it was missing the "$(InputDir) part when compiling a shared solution.
                Moreover, when attempting to compile a static one, it was entirely missing its custom build step. Filling those fields allowed for the generation of the required moc file. To coin a really bad pun, making it part of the solution made it no longer part of the problem.

                I only hope one day to be as knoweldgable as you folks so that I could eventually pay it forward. In the mean time, the fine people on this forum have my gratitude.

                Problem solved.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mlong
                  wrote on 22 Feb 2012, 02:48 last edited by
                  #8

                  Glad you got your problem taken care of! Please be sure and edit the first post and change the thread title to add [Solved]. Thanks!

                  Software Engineer
                  My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                  1 Reply Last reply
                  0

                  1/8

                  17 Feb 2012, 14:19

                  • Login

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