Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt Creator can't compile code from Learn QT 5



  • Hi,,

    I am reading chapter 2 from Learn Qt 5 and after typing in a lot of code, I can't make qt creator to compile it.
    Here they are:
    ...\cm\cm-lib\source\models\client.cpp:3: error: expected unqualified-id
    ....\cm\cm-lib\source\models\client.cpp:3:3: error: expected unqualified-id
    cm-lib::cm-lib()
    ^

    What's more, you cannot follow the book exactly, for example when you create a lib, there's no way to find 'Classs information dialogue'. Nor can you find Qt Unit Test. The user interface has changed a lot.

    It even spits out rubbish such as 'width' is an invalid property name.

    Well, I understand that I am using a community version. But this company shouldn't give away buggy software. They must have seen the bug without us reporting it later.

    I am new to QML. What should I do if even a 2-year-old book which teaches you Qt 5 contains code that Qt 5 doesn't compile?

    Thank you for reading.


  • Moderators

    hi @learnqt

    Can you show your actual source code, this looks like a misplaced ; to me

    It is true, Qt Creator has changed a lot in the last 2 years. But nothing so much, that things are at completely different locations

    But this company shouldn't give away buggy software

    that is true, sadly nearly every company uses the customer as beta testers these days! Despicable but sadly the norm. I Miss the days where software had to be good on release, because online patching wasn't a thing. Today we get day 1 patches bigger then the distributable 😞

    They must have seen the bug without us reporting it later.

    what bug?

    I am new to QML. What should I do if even a 2-year-old book which teaches you Qt 5 contains code that Qt 5 doesn't compile?

    If code compiled 2 years ago, it will compile today, thats a fundamental thing even to c++ in general. And Qt is guaranteed to be compatible inside a major version ( Qt 4 /5/6 are not necessarily compatible to each other)



  • @J-Hilk

    Thanks for the quick answer. It’s a lot of code, but you can download the source from here: https://github.com/PacktPublishing/Learn-Qt-5

    At first I thought I had made some typos so I downloaded the source and strangely it didn’t compile. Please try the ‘cm’ code in chapter 2.


  • Moderators

    @learnqt compiles, links and runs just fine

    fa4bcbdb-0b99-4a52-a3df-ade58d4fec4d-image.png



  • I am running windows 7. You're running a MAC i think. And I can see that you didn't build for android.

    Here's what I did. I doubleclicked on the .pro file and it opened in Qt Creator. I clicked on build. Here's the result.

    Untitled.png



  • Oh. Never mind. I have solved it.
    I disabled the kit for android. And everything is fine now.

    Thank you for help. You showed me that if it ran on your computer I must have been doing something wrong.


  • Moderators

    @learnqt
    actually the creator of this "book" did mess up things as well.

    first of,
    .user files should NEVER EVER be part of a repository and belong into .gitIgnore as they will cause more problems

    secondly, both the test and the ui project depend on the library project. But that is not specified in the cm.pro file

    so change cm.pro to this content:

    TEMPLATE = subdirs
    
    SUBDIRS += \
        cm-ui \
        cm-lib \
        cm-tests
    
    cm-ui.depends = cm-lib
    cm-tests.depends = cm-lib
    message(cm project dir: $${PWD})
    

    Here's what I did. I doubleclicked on the .pro file and it opened in Qt Creator. I clicked on build. Here's the result.

    If you open the project that way, than the default executable will be the test. Testing is not cross platform and will probably fail somehow if you try to build it for android!

    Make sure you select the cm-ui project before compiling:
    40782f93-e7a4-4f89-afcc-8da3cdf7046d-image.png



  • Thank you very much.


Log in to reply