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. A few design questions...
Forum Updated to NodeBB v4.3 + New Features

A few design questions...

Scheduled Pinned Locked Moved General and Desktop
127 Posts 7 Posters 105.4k 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #24

    Now THAT'S a good idea, and will obviate the issue completely. But...makefiles are automatically generated, right? How can I do this in such a way that will survive blowing away the makefile and regenerating it?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #25

      read the qmake docs. I'm sure there is some possibility, but I never needed that :-)

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #26

        But...it's not really a qmake function, is it? Because this special behavior should survive the makefile. Is there a way to do this in the project file?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #27

          but the *.pro files are described in the qmake "documentation":http://doc.qt.nokia.com/latest/qmake-manual.html

          "lmgtfy":http://www.lmgtfy.com/?q=qmake+adding+copy

          e.g. "this page":http://paulf.free.fr/undocumented_qmake.html

          or this on "stackoverflow":http://stackoverflow.com/questions/3984104/qmake-how-to-copy-a-file-to-the-output

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            ZapB
            wrote on last edited by
            #28

            You can do this by defining a custom target in your .pro file. Something like this will do it:

            @
            myresources.path = $$(MY_INSTALL_ROOT)/resources
            myresources.files = myqmlfile.qml

            INSTALLS += target myresources
            @

            The above depends upon the environment variable $MY_INSTALL_ROOT being set. However, this hardcodes the install path.

            Instead, it is better to get rid of the $$(MY_INSTALL_ROOT) part of the path and use the DESTDIR feature of make to specify your installation root:

            @make DESTDIR=/my/installation/path install@

            That separates the install path from your project files.

            Nokia Certified Qt Specialist
            Interested in hearing about Qt related work

            1 Reply Last reply
            0
            • mzimmersM Offline
              mzimmersM Offline
              mzimmers
              wrote on last edited by
              #29

              Sorry if I seem a little slow on the uptake here -- I'm coping with multiple unfamiliar concepts. It's been over 20 years since I've used makefiles, and I'm still trying to figure out project files, qmake, QDir and other stuff.

              Zap: I like the way your approach looks. I can't find anything on DESTDIR in the docs, though. It's not clear to me how this approach obviates the hardcoding issue; it seems to just postpone it. Obviously I'm not understanding the whole thing.

              Thanks.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #30

                First: Go with the Resource directory in the application bundle. That's the expected path on OS X. One should not change those things only when it is absolutely necessary.

                qmake has support for adding additional files to the bundle:

                @
                APP_QML_FILES.files = path/to/file1.qml path/to/file2.qml
                APP_QML_FILES.path = Contents/Resources
                QMAKE_BUNDLE_DATA += APP_QML_FILES
                @

                This installes the files to YourFancyApplication.app/Contents/Resources - just where it belongs on OS X :)

                EDIT: Some more background links in the new "wiki article":http://developer.qt.nokia.com/wiki/Resource_files_in_OS_X_bundle

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

                1 Reply Last reply
                0
                • mzimmersM Offline
                  mzimmersM Offline
                  mzimmers
                  wrote on last edited by
                  #31

                  Thanks, Volker. I realize that files should be in the application bundle, and I wasn't suggesting to do it a different way. In the back of my mind, though, I'm wondering what that bundle looks like when copied to a PC. I'm hoping it's a directory.

                  Do I correctly assume the path/to refers to the path to the source code? Or is that the target?

                  EDIT:

                  I tried it two ways:
                  @APP_QML_FILES.files = ./DemodShaperFilter.qml
                  APP_QML_FILES.path = Contents/Resources
                  QMAKE_BUNDLE_DATA += APP_QML_FILES
                  @

                  and:
                  @APP_QML_FILES.files = DemodShaperFilter.qml
                  APP_QML_FILES.path = Contents/Resources
                  QMAKE_BUNDLE_DATA += APP_QML_FILES
                  @

                  Neither put the file into the Resources folder. It appears that the path is required, which surprises me, because I figured that the .pro file would use its own directory as the default.

                  So now, the question is: is there some slick way to derive the current path from an environment variable or something, and plug it into the .pro file automatically?

                  I'm not pursuing this level of automation out of laziness; it's more a matter of having one less thing to remember when stuff gets changed.

                  Thanks.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #32

                    [quote author="mzimmers" date="1301602502"]Thanks, Volker. I realize that files should be in the application bundle, and I wasn't suggesting to do it a different way. In the back of my mind, though, I'm wondering what that bundle looks like when copied to a PC. I'm hoping it's a directory.

                    Do I correctly assume the path/to refers to the path to the source code? Or is that the target?[/quote]

                    Thats the path of the source. The target path (relative to the bundle) is in the second line.

                    If you just care about copying the Mac bundle to a windows box, then you're right, it is nothing more than an ordinary directory. On the Mac command line you just "cd" into it, like into every other directory. It's just the Finder that displays the bundle differently and if you call "open myprogram.app" on the command line, it does not open Finder (like for directories) but launches the application.

                    Regarding deployment on Windows, that's a different beast. You'll probably consider using an installer to put everything in place. You find some hints on windows installers in "this thread":http://developer.qt.nokia.com/forums/viewthread/4498

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

                    1 Reply Last reply
                    0
                    • mzimmersM Offline
                      mzimmersM Offline
                      mzimmers
                      wrote on last edited by
                      #33

                      Volker: you posted about the same time I edited my last post, so I'm not sure if you saw my new comments/questions?

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on last edited by
                        #34

                        The path is relative to the location of your .pro file.

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

                        1 Reply Last reply
                        0
                        • mzimmersM Offline
                          mzimmersM Offline
                          mzimmers
                          wrote on last edited by
                          #35

                          Hmm...well, then it should have worked, no?

                          What totally obvious thing am I overlooking? I could post the entire .pro file if that would help.

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            goetz
                            wrote on last edited by
                            #36

                            Yep, it should have worked. Is the QML file in a subdirectory?

                            You can try with a test file like this:

                            @
                            APP_QML_FILES.files = Makefile
                            APP_QML_FILES.path = Contents/Resources
                            QMAKE_BUNDLE_DATA += APP_QML_FILES
                            @

                            Not that a Makefile in the Resources is very useful, but it serves well for demonstration purposes :-)

                            For another test, you could add the absolute path to the QML to APP_QML_FILES.files.

                            And as a third guess, do you use shadow builds?

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

                            1 Reply Last reply
                            0
                            • mzimmersM Offline
                              mzimmersM Offline
                              mzimmers
                              wrote on last edited by
                              #37

                              QML file is in same directory as .pro file.

                              Regarding adding the absolute path: I'll re-ask my question of whether there's a way to do it symbolically. Otherwise, it doesn't really solve the problem.

                              Shadow builds: I have a parallel directory to my source, called NNN-build-desktop. That's where all my built files go to live. Is that a shadow build, and if so, is it a bad thing, and if so, how do I do something else?

                              Thanks.

                              1 Reply Last reply
                              0
                              • G Offline
                                G Offline
                                goetz
                                wrote on last edited by
                                #38

                                I don't know about a function that returns the path of the .pro file. As far as I remember this question raised in the forums some time ago.

                                Shadow builds are not a problem. I just checked with my test project. (EDIT: yep, the parallel directory is a shadow build)

                                It must be something different, probably a typo or so. You can post the .pro file here and the contents of your directory, so we can check again. If you don't want to expose your data publicly, contact me via private message to negotiate a "secure" channel.

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

                                1 Reply Last reply
                                0
                                • mzimmersM Offline
                                  mzimmersM Offline
                                  mzimmers
                                  wrote on last edited by
                                  #39

                                  No, I think it's safe to share filenames, for now at least.

                                  Here's the .pro file:

                                  @######################################################################

                                  Automatically generated by qmake (2.01a) Mon Mar 28 17:09:16 2011

                                  ######################################################################

                                  TEMPLATE = app
                                  TARGET =
                                  DEPENDPATH += . headers src
                                  INCLUDEPATH += . headers

                                  APP_QML_FILES.files = DemodShaperFilter.qml
                                  APP_QML_FILES.path = Contents/Resources
                                  QMAKE_BUNDLE_DATA += APP_QML_FILES

                                  QT += declarative

                                  Input

                                  HEADERS +=
                                  headers/clock.h
                                  headers/DemodShaperFilter.h
                                  headers/globals.h
                                  headers/register_offsets.h
                                  headers/Soc.h
                                  headers/SocReg.h
                                  headers/widget.h
                                  headers/GenericCell.h
                                  SOURCES +=
                                  src/clock.cpp
                                  src/DemodShaperFilter.cpp
                                  src/filestuff.cpp
                                  src/globals.cpp
                                  src/main.cpp
                                  src/Soc.cpp
                                  src/SocReg.cpp
                                  src/widget.cpp
                                  src/GenericCell.cpp

                                  FORMS +=
                                  widget.ui

                                  OTHER_FILES +=
                                  DemodShaperFilter.qml
                                  @

                                  And here's a snapshot of my directory:

                                  !http://www.scopedin.com/images/screen.jpg(directory)!

                                  Thanks...

                                  1 Reply Last reply
                                  0
                                  • mzimmersM Offline
                                    mzimmersM Offline
                                    mzimmers
                                    wrote on last edited by
                                    #40

                                    I found the problem: Contents/Resources isn't where the executable is; it's in Contents/MacOS. Works fine now.

                                    That was a nice diversion; now I'll get back to trying to do what Zap mentioned several posts ago. I'll be back with questions about that soon.

                                    1 Reply Last reply
                                    0
                                    • mzimmersM Offline
                                      mzimmersM Offline
                                      mzimmers
                                      wrote on last edited by
                                      #41

                                      So, Zap: from reading the section on Q_PROPERTY, it appears that within my top-level class, I replace the variable creation with a Q_PROPERTY. So, instead of:

                                      @int combGainI;@

                                      I'll now have something like:

                                      @ Q_PROPERTY (int combGainI READ readFn WRITE writeFn);
                                      @

                                      Correct so far?

                                      So, since I have to supply a read and write function, am I correct in assuming that this can no longer be an int? I have to make a class for the combGain, and provide gets and sets for it?

                                      Thanks.

                                      1 Reply Last reply
                                      0
                                      • Z Offline
                                        Z Offline
                                        ZapB
                                        wrote on last edited by
                                        #42

                                        You need the Q_PROPERTY declaration as well as not instead of your normal member variable declaration. This aspect yoru class might look something like this:

                                        @
                                        class MyClass : public QObject
                                        {
                                        Q_OBJECT
                                        Q_PROPERTY( int combGainl READ combGainl WRITE setCombGainl NOTIFY combGainlChanged )

                                        public:
                                        ...
                                        void setCombGainl( int combGainl )
                                        {
                                        // Only emit signal if new value is different
                                        if ( m_combGainl == combGainl )
                                        return;
                                        m_combGainl = combGainl;
                                        emit combGainlChanged( m_combGainl );
                                        }

                                        int combGainl() const { return m_combGainl; }
                                        

                                        signals:
                                        void combGainlChanged( int );

                                        private:
                                        int m_combGainl;
                                        };
                                        @

                                        The important aspects here are:

                                        You still need to decalre the member as usual

                                        You need to provide a getter method

                                        If you declare the property as writeable (from outside the class) as I have illustrated here, then you must provide a setter function too. It is important (to minimise updates and to break circular dependencies between bound properties) that the setter function only emits the property changed notification signal when it does actually change.

                                        If the variable exposed as a property is purely calculated internally then you do not need to expose it as a writeable property. However, you do need to emit the combGainlChanged( int ) signal when you calculate a new value for it. This is used by the QML framework to update QML items that have properties bound to this property.

                                        I hope all of that makes sense. It will become clear when you get your first C++/QML example working.

                                        As for the property types, you can use any type known to Qt's metatype system (look up Q_DECLARE_METATYPE and qRegisterMetaType in the docs). So all the built in types (int, double, etc. plus all the types handled by QVariant work fine out of the box).

                                        Nokia Certified Qt Specialist
                                        Interested in hearing about Qt related work

                                        1 Reply Last reply
                                        0
                                        • G Offline
                                          G Offline
                                          goetz
                                          wrote on last edited by
                                          #43

                                          [quote author="mzimmers" date="1301619372"]I found the problem: Contents/Resources isn't where the executable is; it's in Contents/MacOS. Works fine now.

                                          That was a nice diversion; now I'll get back to trying to do what Zap mentioned several posts ago. I'll be back with questions about that soon.[/quote]

                                          But it got copied into Contents/Resources?

                                          A good way would be to put it there and adapt the search paths in your application (wrapped in some #ifdef):

                                          @
                                          #if defined( Q_OS_MACX )
                                          declarativeEngine.addImportPath(qApp->applicationDirPath() + "/../Resources");
                                          #endif
                                          @

                                          (I've not tested it, you might use another path setter/adder for this)

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

                                          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