Results 1 to 13 of 13

Thread: Need help with QToolButton

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    4
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Need help with QToolButton

    Quote Originally Posted by jpn View Post
    Store toolbar_but as a member variable. The toolbar_but in addButton() is different than in addToolBar(). It's just a dangling pointer in addButton().
    I understand you. But how can I realise it? Toolbutton belongs to mainwindow and I call him in a dock window.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Need help with QToolButton

    Sorry, I didn't understand. Realise what? You mean how can it be implemented?

    Qt Code:
    1. // class declaration
    2. class MainWindow : public ...
    3. {
    4. public:
    5. ...
    6.  
    7. private:
    8. QToolBar* toolbar_but; // <--- a member variable
    9. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // class implementation
    2. void MainWindow::addToolBar()
    3. {
    4. // store the toolbar as a member variable for later usage
    5. toolbar_but = new QToolBar("Open puctures",this, DockLeft , TRUE ,0);
    6. }
    7.  
    8. void MainWindow::addButton()
    9. {
    10. // use the member variable here
    11. btnpix = new QToolButton(toolbar_but, "");
    12. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    philipp1 (27th October 2006)

  4. #3
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    4
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Need help with QToolButton

    I made as you say from the wery beginning.


    class MainWindow : public QMainWindow {
    Q_OBJECT

    public:
    ....
    QToolBar* toolbar_but;
    void addToolBar();
    void addButton();

    mainwindow.cpp

    void MainWindow::addButton()
    {
    //QToolBar* toolbar_but;
    btnpix = new QToolButton(toolbar_but, "");
    }

    void MainWindow::addToolBar()
    {
    QToolBar* toolbar_but = new QToolBar("Open puctures",this, DockLeft , TRUE ,0);

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Need help with QToolButton

    Quote Originally Posted by philipp1 View Post
    I made as you say from the wery beginning.

    Qt Code:
    1. void MainWindow::addToolBar()
    2. {
    3. // the problem is in here
    4. QToolBar* toolbar_but = new QToolBar("Open puctures",this, DockLeft , TRUE ,0);
    5. }
    To copy to clipboard, switch view to plain text mode 
    You are storing the toolbar to a local variable, not to the member variable. It should be:
    Qt Code:
    1. void MainWindow::addToolBar()
    2. {
    3. // notice the missing type, you want to use the member variable, not to create a new local variable
    4. toolbar_but = new QToolBar("Open puctures",this, DockLeft , TRUE ,0);
    5. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    philipp1 (27th October 2006)

  7. #5
    Join Date
    Oct 2006
    Posts
    11
    Thanks
    4
    Qt products
    Qt3
    Platforms
    Unix/X11

    Smile Re: Need help with QToolButton

    Quote Originally Posted by jpn View Post
    You are storing the toolbar to a local variable, not to the member variable. It should be:
    Qt Code:
    1. void MainWindow::addToolBar()
    2. {
    3. // notice the missing type, you want to use the member variable, not to create a new local variable
    4. toolbar_but = new QToolBar("Open puctures",this, DockLeft , TRUE ,0);
    5. }
    To copy to clipboard, switch view to plain text mode 
    Have a great thanks from me. Puting types was my mistake.
    //(may be its friday)

Similar Threads

  1. Cannot hide QToolButton
    By munna in forum Qt Programming
    Replies: 3
    Last Post: 2nd October 2006, 09:41
  2. Problem with qtoolbutton
    By moowy in forum Qt Programming
    Replies: 1
    Last Post: 22nd September 2006, 13:30
  3. Need help with QToolButton
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 22nd April 2006, 14:55

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.