469,268 Members | 991 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,268 developers. It's quick & easy.

No taskbar button with qt

dzenanz
45
I had a small project based on Qt4, ITK and OpenSceneGraph. It's main function is shown below.
Expand|Select|Wrap|Line Numbers
  1. int main( int argc, char **argv )
  2. {
  3.     QApplication app(argc, argv);
  4.     MainWindow mainForm = new MainWindow();
  5.     mainForm.show();
  6.     return app.exec();    
  7. }
There was a problem, however. The window had no taskbar button. I spent quite some time figuring it out, and in the end it all came down to a very stupid difference: main form was instantiated with new operator.

The code that produces a normal window with taskbar:
Expand|Select|Wrap|Line Numbers
  1. int main( int argc, char **argv )
  2. {
  3.     QApplication app(argc, argv);
  4.     MainWindow mainForm;
  5.     mainForm.show();
  6.     return app.exec();    
  7. }
I am not sure weather this trick would work in other circumstances/platforms (I am using Windows XP/VisualStudio2008).

I hope this will help someone with same/similar problem.

Keywords (to increase visibility in search engines):
Qt, osg, hide taskbar button, display taskbar button, opengl, main window
Mar 26 '09 #1
10 8002
weaknessforcats
9,208 Expert Mod 8TB
The C++ new operator returns rthe address of the MainWindow object and not the object itself.

You need code like trhat works with a MainWindow pointer:
Expand|Select|Wrap|Line Numbers
  1. int main( int argc, char **argv ) 
  2.     QApplication app(argc, argv); 
  3.     MainWindow* mainForm = new MainWindow; 
  4.     mainForm->show(); 
  5.     return app.exec();     
Mar 26 '09 #2
dzenanz
45
But the point is, everything worked (main window would show, you could alt-tab to it, etc), there was only no taskbar button.

And you are right, I can try that when I get to work. I did not notice it because compiler did not issue a warning/error about it!
Mar 26 '09 #3
weaknessforcats
9,208 Expert Mod 8TB
You will need to look at the code for MainWindow. You are calling the default constructor. There should be code there to create your task bar.

Expand|Select|Wrap|Line Numbers
  1. MainWindow* mainForm = new MainWindow;  
  2.  MainWindow mainForm; 
In each case above the MainWindow default constructor is called. In the first case the new operator returns the address of the object and in the second case the object is created as a local stack variable. That means in both cases you should get the same results.

The only difference is that using the new operator requires you to delete the pointer when you are done with it.
Mar 26 '09 #4
dzenanz
45
Incredible! You were right. When I use MainWindow *mainForm=new ... instead of MainWindow mainForm=new ... it also works normally. Makes me wonder even more why did compiler allow it, and why the whole thing worked (except the taskbar button, of course). MainWindow is a wrapper for something made in designer.
Expand|Select|Wrap|Line Numbers
  1. class MainWindow : public QMainWindow, public Ui::mainWindow
  2. {
  3.     Q_OBJECT
  4.  
  5. public:
  6.     using Ui::mainWindow::centralWidget;
  7.     MainWindow(QWidget *parent = 0);
  8.  
  9. protected:
  10.     void closeEvent(QCloseEvent *event);
  11.     void resizeEvent( QResizeEvent * event );
  12.  
  13. signals:
  14.     void fileOpened(std::string filename);
  15.  
  16. private slots:
  17.     void on_actionOpen_activated();
  18. };
Mar 27 '09 #5
weaknessforcats
9,208 Expert Mod 8TB
Your code does not compile using C++. That is:

Expand|Select|Wrap|Line Numbers
  1.    MainWindow mainForm = new MainWindow;  
is in error as far as C++ is concerned. It has to be:

Expand|Select|Wrap|Line Numbers
  1. MainWindow* mainForm = new MainWindow; 
Now I am not familiar with exactly what compiler you are using but whatever it is, it is not following C++ rules. Maybe you are using a C++-look-alike language that has different rules.
Mar 27 '09 #6
dzenanz
45
:D

I am using Microsoft Visual C++ 2008 IDE/compiler. Compiler not screaming about it must have something to do with Qt's additions.
Mar 27 '09 #7
weaknessforcats
9,208 Expert Mod 8TB
I am also using Microsoft Visual C++ 2008 IDE/compiler.

I have a C++ console application project and your code does not compile when you use the new operator assigning to an object rather than a pointer to an object.

Here is my error:
error C2440: 'initializing' : cannot convert from 'MainWindow *' to 'MainWindow'
generated from:

Expand|Select|Wrap|Line Numbers
  1. MainWindow mainForm = new MainWindow;  
whereas

Expand|Select|Wrap|Line Numbers
  1. MainWindow* mainForm = new MainWindow;  
compiles fine.
Mar 27 '09 #8
dzenanz
45
This program also uses OpenSceneGraph and InsightToolKit. If you have them on your system, maybe I can send you the entire project. Or I could rip those 2 out to make a minimal proof-of-concept example. I am in the beginning of starting a new project, so that should not be so hard. Maybe I can go tomorrow to workplace (University to be exact :D) to do it.

Of course, you have to be interested :D
Mar 27 '09 #9
weaknessforcats
9,208 Expert Mod 8TB
A proof-of-concept example would be interesting but more than that, step through your code using the debugger. Especially when using the C++ new operator assigning to a MainWindow object (the case that should not compile but does somehow on your machine).

That's all I would do myself.
Mar 28 '09 #10
JosAH
11,448 Expert 8TB
I don't know what this thread did in the 'insights' section but it belongs here in the normal forum: it is not an article by far ...

kind regards,

Jos
Mar 29 '09 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Wes | last post: by
reply views Thread by Chris DiPierro | last post: by
6 posts views Thread by Mark | last post: by
1 post views Thread by German Garbuglia | last post: by
2 posts views Thread by hohrin | last post: by
2 posts views Thread by Paul E Collins | last post: by
8 posts views Thread by DarkBlue | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.