Results 1 to 3 of 3

Thread: Connect to...without slots...

  1. #1
    Join Date
    Oct 2009
    Posts
    70
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Connect to...without slots...

    I have code:
    Qt Code:
    1. int main(int argv, char * argc[])
    2. {
    3. QApplication app(argv,argc);
    4.  
    5. QWidget* window = new QWidget;
    6.  
    7. window->setGeometry(QRect(200,200,300,300));
    8. window->setWindowTitle("QFileDialog example");
    9. window->setMaximumSize(300,300);
    10. window->setMinimumSize(300,300);
    11.  
    12. QPushButton *newFile = new QPushButton("New File Dialog");
    13. newFile->setGeometry(QRect(50,25,250,35));
    14.  
    15.  
    16. QPushButton *saveFile = new QPushButton("Save File Dialog");
    17. saveFile->setGeometry(QRect(50,75,250,35));
    18.  
    19.  
    20. QGridLayout *layout = new QGridLayout;
    21. layout->addWidget(newFile,0,0,1,1,Qt::AlignHCenter);
    22. layout->addWidget(saveFile,1,0,1,1,Qt::AlignHCenter);
    23.  
    24. window->connect(...); // ?
    25.  
    26.  
    27. window->setLayout(layout);
    28. window->show();
    To copy to clipboard, switch view to plain text mode 

    I need to connect button with function ( I don't have class )
    something like:
    Qt Code:
    1. window->connect(newFile,SIGNAL(cliecked()),newFile,SLOT( myImaginedFunc()));
    To copy to clipboard, switch view to plain text mode 
    doesn't work because it calls:
    Qt Code:
    1. QPushButton::myImaginedFunc()
    To copy to clipboard, switch view to plain text mode 
    which doesn't exist.

  2. #2
    Join Date
    Mar 2008
    Posts
    27
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Connect to...without slots...

    You could try to write a new function which would be located underneeth (or above) your main() function.

    your connect statement would be something like:
    Qt Code:
    1. window->connect(newFile,SIGNAL(clicked()),this,SLOT( myImaginedFunc()));
    To copy to clipboard, switch view to plain text mode 

    I can imagine that you would have to define 'myImaginedFunc()' as a slot somewhere. I don't know if this can be done in your .cpp file. You might want to create a .h file to do this in.

    If this doesn't work, it might be easier to just create a class from which you create your window. The slot can be defined in this class.

    Good luck.

  3. #3
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Connect to...without slots...

    I think you can create an auxiliary class which will have your function and yhis function will be declared as a slot. In this case your connect statement will be valid.

    But in general, I think this is not a normal situation and i think you need to review your application's design.
    I'm a rebel in the S.D.G.

Similar Threads

  1. Application only 'animates' once
    By arkain in forum Qt Programming
    Replies: 7
    Last Post: 29th April 2009, 08:09
  2. Replies: 12
    Last Post: 23rd June 2008, 08:05
  3. Connecting to Undeclared Slots
    By Dumbledore in forum Qt Tools
    Replies: 5
    Last Post: 11th October 2007, 17:19
  4. function 'connect' always look super class for slots.
    By Intaek Lim in forum Qt Programming
    Replies: 7
    Last Post: 12th March 2007, 13:38
  5. Adding slots in Designer
    By jamos in forum Qt Tools
    Replies: 5
    Last Post: 18th May 2006, 23:28

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.