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

Strange app crash issue



  • Hello!

    This is my first time posting in the Qt forums and I hope I am posting in the correct location; if I am not, please forgive me and redirect me.

    So, the error that I am receiving doesn't offer much information or indicate as to what may be going wrong, it just says "The program has unexpectedly finished. The process was ended forcefully." If I were to take a stab at it, I would say it's a compiler issue, but still, I do not know where to begin to solve this.

    If we look at the code, I set up 'piece' to hold a bunch of characteristics before I add to it my 'mod' object, which is a DataModule that contains a member type QList<DataPiece>. You can see from the console that we get to "here", which is directly before the function call; the second screenshot gives you a look at the function addData(), which just calls the push_back() method to place the item at the end of the list. The item is added successfully too, because when we call the size() method, 1 is correctly printed in the console. However, the line after the addData() function call, "data piece loaded", never gets printed! The program mysteriously drops at this very point with no strong indication as to what is going on.

    Now, I am not sure if these two issues are related, but I am having another issue with the Meta Object Compiler (reference the 3rd screenshot). Every time I go to rebuild my project, I get this error, "no match for call to '(Qstring) ()'. This is currently happening to 3 of my classes, all of which I have used the Q_OBJECT & Q_PROPERTY macros. I will add in some pictures of the header files to show you how I used those. Temporarily, I could fix this error by either: a) removing the '()' from the end of 'value', 'units', etc., or b) capitalizing each first letter of those function calls to match the definitions in my header files. Either way I go, I am able to get the program running. What's annoying, is that every time I go to rebuild the project, I have to go in to these moc_ files and manually edit specific lines. If I rebuild again, QtCreator prompts be to reload the moc file I changed. Is there something I am doing to confuse the compiler/MOC? Fairly new to Qt, so I am sure it's something I am doing.

    Let me know if you need to see more code or more information.

    Thanks in advance!

    0_1528892149785_strange.png 0_1528892163153_strange1.png 0_1528892912442_moc.png 0_1528893527337_datapiece_mocerror.png

    0_1528893531826_datamodule_mocerror.png 0_1528893535587_data_model_mocerror.png


  • Lifetime Qt Champion

    Hi,

    You should make your constructor taking a QString explicit, otherwise there will be some strange implicit conversion behaviour.

    Also, you should rather use const references when passing complex class a parameters, you are doing a lot of useless copies.

    Finally, I'd recommend making your getter const, unless you are modify your class in them.



  • Got it, thanks SGaist! Although I am great at following directions, I like to understand things. That being said, in what situations is it appropriate to use 'const'? Obviously when a value isn't supposed to change; but how does this ultimately simplify the process? I remember a few days ago I was running into a lot of copy constructor errors, does these two things have a correlation?

    Also, what purpose does 'explicit' serve? From what I gathered from another post, it allows you to re-initialize a pre-existing object by re-calling its constructor. Example:

    class MyObj
    {
    public:
    explicit MyObj(int size): m_size(size) {}
    private:
    int m_size;
    };

    ...
    void A::someMethod()
    {
    MyObj mw(10);
    mw = 5;//compile error; explicit conversion is needed.
    mw = MyObj(5);//ok
    }

    How accurate am I with that? Is there something I am missing from that understanding?

    PS... Discovered the fix to make MOC happy. I made sure that the READ function defined inside of each Q_PROPERTY matched the getter inside the class definition.

    I should also say that neither of these fixes resolved the program crashing issue.



  • One more thing: this should have been one of my first things I tried, but I ran the debugger and got the following message - "The inferior stopped because it received a signal from the operating system
    Signal name: SIGSEGV
    Signal meaning: Segmentation fault",

    and it pointed directly at my destructor for DataPiece, which simply calls "delete this" (even though I never actually call the destructor in my code, it must be an implicit call).

    After briefly looking up this error, I primitively discovered that this generally occurs when attempting to illegally access a register in memory. So then I looked at how I initialized my DataPiece, realizing that I actually wasn't calling any of my constructors. So, I passed it a parameter 'this' to act as the QObject * parent, but this still didn't resolve my SIGSEGV issue.

    Any thoughts?


Log in to reply