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. isWindowModified is no effect
Forum Updated to NodeBB v4.3 + New Features

isWindowModified is no effect

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.3k Views 1 Watching
  • 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.
  • chaochaoC Offline
    chaochaoC Offline
    chaochao
    wrote on last edited by
    #1

    I create a winow called NoteBook and include a textedit object.Create an action called new and connect a slot called newFile.```
    //
    void MainWindow::newFile()
    {
    if(okTocontinue())
    {
    _textedit->clear();
    setCurrentFile("");
    }
    }
    bool MainWindow::okTocontinue()
    {
    if (isWindowModified()) {
    qDebug()<<" modify";
    int r = QMessageBox::warning(this, tr("NoteBook"),
    tr("The document has been modified.\n"
    "Do you want to save your changes?"),
    QMessageBox::Yes | QMessageBox::No
    | QMessageBox::Cancel);
    if (r == QMessageBox::Yes) {
    return saveFile();
    } else if (r == QMessageBox::Cancel) {
    return false;
    }
    }
    qDebug()<<"not modify";
    return true;
    }

    I have typed some character in textedit,but it always debug "not modify.I donot know what happened. Thank for your help.
    jsulmJ 1 Reply Last reply
    0
    • chaochaoC chaochao

      I create a winow called NoteBook and include a textedit object.Create an action called new and connect a slot called newFile.```
      //
      void MainWindow::newFile()
      {
      if(okTocontinue())
      {
      _textedit->clear();
      setCurrentFile("");
      }
      }
      bool MainWindow::okTocontinue()
      {
      if (isWindowModified()) {
      qDebug()<<" modify";
      int r = QMessageBox::warning(this, tr("NoteBook"),
      tr("The document has been modified.\n"
      "Do you want to save your changes?"),
      QMessageBox::Yes | QMessageBox::No
      | QMessageBox::Cancel);
      if (r == QMessageBox::Yes) {
      return saveFile();
      } else if (r == QMessageBox::Cancel) {
      return false;
      }
      }
      qDebug()<<"not modify";
      return true;
      }

      I have typed some character in textedit,but it always debug "not modify.I donot know what happened. Thank for your help.
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @chaochao As far as I know you have to call setWindowModified() whenever your document is modified. MainWindow cannot know when it is modified as it can contain many widgets and it does not know what the logic of your application is. See this example: http://doc.qt.io/qt-5/qtwidgets-mainwindows-application-example.html

      MainWindow::MainWindow()
          : textEdit(new QPlainTextEdit)
      {
          connect(textEdit->document(), &QTextDocument::contentsChanged,
                  this, &MainWindow::documentWasModified);
      }
      void MainWindow::documentWasModified()
      {
          setWindowModified(textEdit->document()->isModified());
      }
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      chaochaoC 1 Reply Last reply
      3
      • jsulmJ jsulm

        @chaochao As far as I know you have to call setWindowModified() whenever your document is modified. MainWindow cannot know when it is modified as it can contain many widgets and it does not know what the logic of your application is. See this example: http://doc.qt.io/qt-5/qtwidgets-mainwindows-application-example.html

        MainWindow::MainWindow()
            : textEdit(new QPlainTextEdit)
        {
            connect(textEdit->document(), &QTextDocument::contentsChanged,
                    this, &MainWindow::documentWasModified);
        }
        void MainWindow::documentWasModified()
        {
            setWindowModified(textEdit->document()->isModified());
        }
        
        chaochaoC Offline
        chaochaoC Offline
        chaochao
        wrote on last edited by
        #3

        @jsulm very thanks,that's very good.When I see this example, I find what i want to realise is similar with that.

        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