Results 1 to 17 of 17

Thread: saveGeometry in X11

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2007
    Posts
    39
    Thanks
    10

    Default saveGeometry in X11

    Hi all

    I am trying to remember the size and location of the mainwindow from previous session in X11. Qt documentation suggests 2 methods:

    1) To use saveGeometry and restoreGeometry. This works fine with saving the size but the position is not consistent. From what I see, the position is remembered for one closeEvent and then from the second time it moves the window to top-left corner.

    2) To save pos and size.

    Doesn't method 1) work for X11?

    Thanks
    Arjun

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

    Default Re: saveGeometry in X11

    Yes, it does work on X11 too.
    How do you do it? Can you show us the code?
    I do not quite understand your explanation at point 1).

    Regards

  3. #3
    Join Date
    Jul 2007
    Posts
    39
    Thanks
    10

    Default Re: saveGeometry in X11

    void writeSettings() {
    QSettings settings("Z", "X");
    settings.setValue("geometry", saveGeometry());
    }


    void readSettings() {
    QSettings settings("Z", "X");
    restoreGeometry(settings.value("geometry").toByteA rray());
    }

    The size is maintained but the position of the window is not remembered at all times. It is remembered only when the position is changed in the current execution.

    Thanks
    Arjun

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

    Default Re: saveGeometry in X11

    Weird enough.
    Could you examine the settings, or the QByteArray, between two sessions?

  5. #5
    Join Date
    Jul 2007
    Posts
    39
    Thanks
    10

    Default Re: saveGeometry in X11

    Sorry if this is a naive question.

    Where do they get saved? Else how to check there contents using qDebug()?

    Thanks
    Arjun

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

    Default Re: saveGeometry in X11

    Probably they are saved in the home directory.
    On Mac they are saved in the app directory.

    Qt Code:
    1. qDebug("%s\n", saveGeometry().constData());
    To copy to clipboard, switch view to plain text mode 

    Regards

  7. #7
    Join Date
    Jul 2007
    Posts
    39
    Thanks
    10

    Default Re: saveGeometry in X11

    qDebug("%s\n", saveGeometry().constData());
    I tried that but its printing some special characters. So I guess I need to go over each byte and print it as a character.

    Is there any other better way to check the contents?

    Thanks
    Arjun

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

    Default Re: saveGeometry in X11

    There should be the coordinates.
    Try
    Qt Code:
    1. QString str(saveGeometry());
    2. qDebug("%s", str.toAscii().constData());
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Jul 2007
    Posts
    39
    Thanks
    10

    Default Re: saveGeometry in X11

    Sorry to bother you again. But it prints the same special characters even now.

    Thanks
    Arjun

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

    Default Re: saveGeometry in X11

    Well, I just read in the docs that this doesn't work on X11( the set/restoreGeometry stuff).
    They suggest using the following:
    Qt Code:
    1. void MainWindow::readSettings()
    2. {
    3. QSettings settings("Trolltech", "Application Example");
    4. QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
    5. QSize size = settings.value("size", QSize(400, 400)).toSize();
    6. resize(size);
    7. move(pos);
    8. }
    9.  
    10. void MainWindow::writeSettings()
    11. {
    12. QSettings settings("Trolltech", "Application Example");
    13. settings.setValue("pos", pos());
    14. settings.setValue("size", size());
    15. }
    To copy to clipboard, switch view to plain text mode 


    Meaning that you must save the geometry manually.
    Should work,

    Regards

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

    arjunasd (7th August 2007)

  12. #11
    Join Date
    Jul 2007
    Posts
    39
    Thanks
    10

    Default Re: saveGeometry in X11

    Marcel

    Thanks a lot.
    Still I would like to know whats being saved. Just out of curiosity. If you know a method to print out the contents of QByteArray, let me know.

    Thanks again for your help
    Arjun

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
  •  
Qt is a trademark of The Qt Company.