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. Customcompleter EXC_BAD_ACCESS crash

Customcompleter EXC_BAD_ACCESS crash

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.1k Views
  • 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.
  • S Offline
    S Offline
    schaafsma.alex
    wrote on last edited by
    #1

    hello,

    im trying to make a simple code editor (just completer, codeeditor and syntaxhighlightin examples in one application).

    now i am getting a EXC_BAD_ACCESS could not access memory error and the app crashes.

    here is the the relevant code

    header:
    @public:
    void setCompleter(QCompleter *completer);
    private:
    QCompleter *c;@

    source:
    @void ACodeEditor::setCompleter(QCompleter *completer)
    {
    if(c) {
    //here is the error!!
    QObject::disconnect(c , 0,
    this, 0);
    }

    c = completer;
    
    if(!c) return;
    
    c->setWidget(this);
    c->setCompletionMode(QCompleter::PopupCompletion);
    c->setCaseSensitivity(Qt::CaseInsensitive);
    QObject::connect(c   , SIGNAL(activated(QString)),
                     this, SLOT  (insertCompletion(QString)));
    

    }@

    for a temporary solution i out-commented line 3 till 6 and it works fine.
    don't really know the consequence is for not disconnecting objects.

    does any one know how to fix this?

    thanks.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bodzio131
      wrote on last edited by
      #2

      Do you use uninitialized 'c' field inside ACodeEditor::setCompleter?

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Do you initialize c to 0 anywhere? If not, "if( c )" will pass(as c is random) and a disconnect on this random c pointer will cause crash.

        Also, you don't seem to delete the old c, so it's a memory leak. You should call c->deleteLater() before overwriting it with new completer.
        As for the disconnecting - it's automatic when the emitting or receiving object is destroyed, so you don't really need it here. Just delete the old completer(via deleteLater()), or all those leaking pointers will still hold connections until the program ends.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          schaafsma.alex
          wrote on last edited by
          #4

          thanks Krzysztof Kawa.

          i changed it in the constructor i have set c = 0 and replaced the diconnect with c->deletelater().
          now it works.

          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