Results 1 to 12 of 12

Thread: Adding nonQt classes to QtApplication

  1. #1
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Adding nonQt classes to QtApplication

    Hello!

    I'm writting my first application (without tutors) and having problems to run it.
    Before anything apeares it ends with Segmentation fault.

    the structuture is something like this:
    I have written a dialog with some buttons, lineedit, a table, etc.
    when i run the program (just the GUI) it works fine.
    so i make one more step.. I include some of my classes.

    when i compile the project it doesn't show any errors. but when i run it... BOOM!
    I just put one line in init():
    myClass= new MyClass();

    i was looking for some getting started on how to add your own classes but found nothing useful.

    Another question: My own classes have to be derivered from QObject?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding nonQt classes to QtApplication

    Another question: My own classes have to be derivered from QObject?
    No, unless you want to emit signals in them or you want implement slots in them.

    was looking for some getting started on how to add your own classes but found nothing useful.
    Nothing special has to be done with non-qt classes. Most likely you get that segfault because of something wrong that happens in the constructor of your class.

    Could we see that class you are trying to instantiate? At least the constructor implementation and the declaration.

    regards
    Last edited by marcel; 22nd April 2007 at 20:12.

  3. #3
    Join Date
    Mar 2007
    Location
    India
    Posts
    27
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: Adding nonQt classes to QtApplication

    Quote Originally Posted by codebehind View Post
    I have written a dialog with some buttons, lineedit, a table, etc.
    when i run the program (just the GUI) it works fine.
    so i make one more step.. I include some of my classes.
    i personally feel, you should try to write your class as the main class and include the GUI object as a member variable in it. this way, all you have to do is initialize the GUI in "your class"'s constructor. all you need to do is call show() after the operations in your class have been done with.

    this way, if there's any segfaults arising out of your class, you will be able to debug better. just a suggestion!

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Adding nonQt classes to QtApplication

    i personally feel, you should try to write your class as the main class and include the GUI object as a member variable in it. this way, all you have to do is initialize the GUI in "your class"'s constructor. all you need to do is call show() after the operations in your class have been done with.

    this way, if there's any segfaults arising out of your class, you will be able to debug better. just a suggestion!
    This is a design question.
    No one can say this is better in his hase, than another solution.
    You should always fit your tools and solutions to the problem you have, and not stick to one tool/solution/design without knowing what the requirements are.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Adding nonQt classes to QtApplication

    Thanx to all!

    i've attached the src. to me it seems every thing OK.

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding nonQt classes to QtApplication

    i've attached the src.
    Well, where is it?

  7. #7
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Adding nonQt classes to QtApplication

    Sorry, I forgot to upload.. :P

    well, th main makefile is in GUI/ dir

  8. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding nonQt classes to QtApplication

    Try again!
    It's the manage attachments button.

  9. The following user says thank you to marcel for this useful post:

    codebehind (23rd April 2007)

  10. #9
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Adding nonQt classes to QtApplication

    Invalid file format... i havent saw the msg
    Attached Files Attached Files

  11. #10
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding nonQt classes to QtApplication

    Ok, here is your mistake, in file Automat.cpp:

    Qt Code:
    1. Automat::Automat()
    2. {
    3. _maxStAkcij=MAX_AKC;
    4. _verAkcije= new double(_maxStAkcij);
    5. //_verAkcije= (double *)malloc(_maxStAkcij);
    6.  
    7. for(int i=0; i < _maxStAkcij; i++)
    8. _verAkcije[i]=1/(float)_maxStAkcij;
    9.  
    10. _kazen = KAZEN;
    11. _nagrada = NAGRADA;
    12. }
    To copy to clipboard, switch view to plain text mode 
    The line:
    Qt Code:
    1. _verAkcije= new double(_maxStAkcij);
    To copy to clipboard, switch view to plain text mode 
    is causing your crash, because will create only ONE double and will assign _maxStAkcij value to it. It crashed in the next for loop, when you populate the array. It will cause a buffer overrun in your array.

    You have to use square brackets to allocate an array. Like this:
    Qt Code:
    1. _verAkcije= new double[_maxStAkcij];
    To copy to clipboard, switch view to plain text mode 
    Try it and it will work.

    Regards
    Last edited by marcel; 23rd April 2007 at 21:04.

  12. The following user says thank you to marcel for this useful post:

    codebehind (23rd April 2007)

  13. #11
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Adding nonQt classes to QtApplication

    I actually don't have Qt3 installed, so I couldn't properly test your code. But I am almost certain that is the error.

    Regards

  14. #12
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Adding nonQt classes to QtApplication

    It works fine. thx again!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.