Results 1 to 5 of 5

Thread: QTextEdit SIGSEGV

  1. #1
    Join Date
    Jan 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default QTextEdit SIGSEGV

    Hello, and sorry for being such a newb by asking, which I believe really is a simple thing.

    Okay, here's the thing.
    I want to do a simple editor, which then will check the input characters and change them to something else, and the
    set them in the QTextEdit.

    What I mean is that, when I write for eg. a 2, it will be checked against a list of characters, and if there's a match, change the 2 into
    a specific text/chars.

    I want it to change my 2 to a G#. But the QTextEdit shouldn't input characters that I don't want, eg. z, x etc.

    And as you may already know, I am newb, just started with Qt yesterday :P
    Im not a complete newb when it comes to C++, even tho it may seem so. I just have a hard time figuring out what needs to be done
    and how to do it "right".

    I've been looking through this forum, the Qt docs and google, but without success.
    So, even if it's against my principles, I decided to ask you guys here at the forum.

    When I execute my program, it gives me the SIGSEV signal when I try to edit the text in my QTextEdit.

    The code looks like this atm:

    dialog.h
    Qt Code:
    1. #ifndef DIALOG_H
    2. #define DIALOG_H
    3.  
    4. #include <QDialog>
    5. #include <QLineEdit>
    6. #include <QLabel>
    7. #include <QTextEdit>
    8.  
    9. class myDialog : public QDialog
    10. {
    11. Q_OBJECT
    12.  
    13. private:
    14.  
    15. QLineEdit* m_lneTitle;
    16. QLabel* m_lTitle;
    17. QTextEdit* m_document;
    18.  
    19. private slots:
    20.  
    21. void textEditSlot();
    22.  
    23. public:
    24.  
    25. myDialog();
    26. virtual ~myDialog(){};
    27. };
    28.  
    29. #endif // DIALOG_H
    To copy to clipboard, switch view to plain text mode 

    dialog.cpp
    Qt Code:
    1. #include "dialog.h"
    2.  
    3. myDialog::myDialog()
    4. {
    5. //fönsterstorlek samt pos. vart den ska vara när app. startas
    6. this->setGeometry(200, 100, 600, 400);
    7.  
    8. //skapa en label
    9. m_lTitle = new QLabel(this);
    10. m_lTitle->setText("Song Title:");
    11. m_lTitle->setGeometry(20, 20, 80, 20);
    12.  
    13. // skapa lineedit, till songtiteln
    14. m_lneTitle = new QLineEdit(this);
    15. m_lneTitle->setGeometry(80, 20, 140, 20);
    16.  
    17. //skapa själva editrutan
    18. m_document = new QTextEdit(this);
    19. m_document->setGeometry(20, 60, 560, 300);
    20.  
    21. //koppla lite signaler
    22. connect(m_document, SIGNAL(textChanged()), this, SLOT(textEditSlot()));
    23. }
    24.  
    25. void myDialog::textEditSlot()
    26. {
    27. // haven't put anything here atm, cuz anything in here makes it crasch. with anything I mean like m_document->setText();
    28. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "dialog.h"
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QApplication app( argc, argv );
    7.  
    8. myDialog* d = new myDialog();
    9. d->show();
    10.  
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    I haven't put any code in the signal slot right now, cuz everything that I tried just crashed the program.

    Is this because of the "SIGNAL(textChanged()"?
    If so, what should I use instead?

    Oh, and I could be satisfied with any solution, I just want to get this to work right now.
    If it's possible to catch the keyboard event, which I assume is, how would I do that and then set the text in the QTextEdit via
    that function?

    The reason I want this to work is because I feel that me and my buddy, who happens to be a way better coder than me, created
    an application in SDL which reads "notes" from a text file, and then output the sound via either the PC-speaker or via the speakers.

    Now you may think: "Well, if your buddy is such a better coder than you, why doesn't he create this?".
    Well, the answer to that is: "Because I want to learn more, I want to "grow"."

    So, please. If you feel like helping me out here, it would be greatly appreciated.

    /Flayer

  2. #2
    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: QTextEdit SIGSEGV

    Please refrain from all the non relevant explanations.
    Just focus on the problem.

    The widget code looks valid to me.
    Can you show what code exactly makes your application crash?
    Does it crash with the empty slot?

    and there is no reason to allocate myDialog on the heap:
    Qt Code:
    1. myDialog d;
    2.  
    3. d.show();
    To copy to clipboard, switch view to plain text mode 
    ==========================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.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit SIGSEGV

    Consider this: in a slot which is executed every time text is changed in the widget you try to change the text. What do you think it leads to?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jan 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextEdit SIGSEGV

    Quote Originally Posted by wysota View Post
    Consider this: in a slot which is executed every time text is changed in the widget you try to change the text. What do you think it leads to?
    Ye, thats what I thought, but what should I use instead?
    How would I acheive the same thing without the "textChanged" or any other that "works" like it, it would just be the same thing.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit SIGSEGV

    I would connect to QTextDocument::contentsChange() signal to detect modifications to the document. In the slot I would check all modified blocks (based on the position) for strings I was searching for. If found, I would prepare a replacement for them. Finally I would make the replacements. You just have to remember to provide some means of making sure you won't fall into an infinite loop - either by making sure replacements and searches are disjoint (i.e. that no part of any replacement will trigger a search match) or by setting a flag "hey, I'm in the middle of replacing, don't fall into the loop". Also a nice although a bit more advanced technique would be to use QTextBlockUserData to mark areas that have been replaced by the mechanism (this would allow to preserve replacements even if they are not disjoint from searches).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. sigsegv ?
    By mero in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2009, 18:01
  2. QSqlQueryModel::setQuery - SIGSEGV
    By onamatic in forum Qt Programming
    Replies: 14
    Last Post: 27th January 2009, 10:26
  3. QAbstractSocket::abort() with SIGSEGV
    By mtrpoland in forum Qt Programming
    Replies: 1
    Last Post: 24th February 2008, 17:05
  4. Program crashes (SIGSEGV)
    By Voldemort in forum Qt Programming
    Replies: 47
    Last Post: 21st May 2007, 20:09
  5. Replies: 1
    Last Post: 16th February 2007, 07:22

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.