SetGeometry: Unable to set geometry



  • I get the warning message: "setGeometry: Unable to set geometry 75x23+640+280 on QWidgetWindow/'QPushButtonClassWindow'. Resulting geometry: 124x23+640+280 (frame: 8, 31, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215)."

    This happens with pretty much every widget. The program itself has no problem running. I'm running some tutorials from a book (written in 2007). The code is:

    @#include <QApplication>
    #include <QPushButton>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    QPushButton button( "quit" );
    button.show();
    
    QObject::connect( &button, SIGNAL(clicked()), &a, SLOT(quit()));
    
    return a.exec&#40;&#41;;
    

    }@

    What is the cause and how do I get rid of this message?



  • In the code , how r you using setGeometry() ??



  • That's the thing. I'm not using it. The code sample I provided is the whole program.
    [quote author="ankursaxena" date="1393408724"]In the code , how r you using setGeometry() ??[/quote]



  • Same problem here, even without line 11.
    Up please ? :/



  • Information please. What Qt version? What platform? What compiler?



  • I am using Qt 5.1.2 32bit (with Qt Creator 3.0.1) on Windows 7 64bit. I don't really know what compiler it is, it came with the MinGW installed with Qt. I used the online installer downloaded here : http://qt-project.org/downloads
    So I guess it must be g++.



  • I was also using the MinGW compiler installed with Qt 5.1.2 64-bit..



  • I'm sure that book from 2007 is a good one, but it's 7 years old, and things for sure have changed in Qt.

    If you want it to run in Qt5 without it complaining about geometry, I'm guessing it nowadays needs a hint/default value for that. Maybe try by inserting one geometry call of your own. e.g.:
    @ #include <QApplication>
    #include <QPushButton>

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
     
        QPushButton button( "quit" );
        button.setGeometry(200,200,200,200);
        button.show();
     
        QObject::connect( &button, SIGNAL(clicked()), &a, SLOT(quit()));
     
        return a.exec(&#41;;
    }@
    

    then it should run without messages :-)



  • Gotta try that, didn't even think about it. Thanks, I will give feedback :)



  • This example is a very old looking way to do it, though it will still work. The problem is the defualt values are going to be "junk" since there is no parent widget to place your button on. I think hskoglund suggestion will certainly fix your issue, but you will make a "floating" button attached to nothing :o

    You are probably better off starting with a Qt Widgets application example which you can create in Qt creator:

    File --> New Project --> Application --> Qt Widgets application

    Then you have a similar startup program, but this time you have a MainWindow on which to put your buttons.



  • So I tried hskoglund's way, and it worked well, no warning this time :)
    I'll try code_fodder's way when I'll start another project with QtGUI.

    Thanks to all !



  • Well done, remember to mark the post as solved by changing the title to
    "[SOLVED] ....title name...."


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.