Results 1 to 18 of 18

Thread: signals and slots, newbie problem

  1. #1
    Join Date
    Jun 2014
    Posts
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default signals and slots, newbie problem

    Hello

    I got a job to do and I came across the problem of a beginner, I do not know yet how to find the signals and slots.

    OK, my problem is that I have declared the two methods in a class and I must conncet with the class Controller using signals and slots. So when you squeeze the button that has to execute method of the class.

    Please help and some examples of solutions.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, newbie problem


  3. #3
    Join Date
    Jun 2014
    Posts
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, newbie problem

    Thanks but ...
    I have class controller.
    I have class Search, where I have slot on_pushButton_clicked()
    and i have c++ class Find, where I have method.
    Program works that, the main windows start, next I click Search Window and on the Search Window i press pushButton and i would like to start method from class Find.
    How connect this 3 things in controller.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, newbie problem

    The linked documentation covers:
    - declaration of a signal
    - declaration of a slot
    - connecting a signal to a slot

    So what kind of additional information are you looking for?

    Cheers,
    _

  5. #5
    Join Date
    Jun 2014
    Posts
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, newbie problem

    I get lost in files.

    SearchWindow.h
    Qt Code:
    1. signals:
    2. void searchButtonSelected();
    3.  
    4. public slots:
    5. void on_pushButton_clicked();
    To copy to clipboard, switch view to plain text mode 

    SearchWindow.cpp
    Qt Code:
    1. void SearchListWindow::on_pushButton_clicked()
    2. {
    3. qDebug() << "Search push button clicked";
    4. emit searchButtonSelected();
    5. }
    To copy to clipboard, switch view to plain text mode 

    Controller.h
    Qt Code:
    1. signals:
    2. void startMethodProcess();
    3.  
    4. private slots:
    5. void searchButtonSelected();
    To copy to clipboard, switch view to plain text mode 

    Controller.cpp
    Qt Code:
    1. void Controller::setupsearchlistwindow(SearchListWindow* searchWindow)
    2. {
    3. connect( ? );
    4. }
    To copy to clipboard, switch view to plain text mode 

    Method.cpp
    Qt Code:
    1. void Method::process();
    To copy to clipboard, switch view to plain text mode 

    How to call method process in connect.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, newbie problem

    Does Controller have a pointer to an instance of Method?
    Do you want Controller::searchButtonSelected() to call Method:rocess() or is Method:rocess() a slot itself?

    Cheers,
    _

  7. #7
    Join Date
    Jun 2014
    Posts
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, newbie problem

    I want to call Method process when button is press

    Controller haven't a pointer to an instance of Method, how make it?

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, newbie problem

    Quote Originally Posted by testQtowiec View Post
    I want to call Method process when button is press
    Yes, but that is not what I was asking.
    Is Method:rocess() a slot, i.e. do you want to connect the signal to it, or is it just a normal method, i.e. do you want to call it inside the slot of Controller?

    Quote Originally Posted by testQtowiec View Post
    Controller haven't a pointer to an instance of Method, how make it?
    Basic C++: create an instance of Method in Controller or pass a Method object to the Controller object.

    Cheers,
    _

  9. #9
    Join Date
    Jun 2014
    Posts
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, newbie problem

    It's normal method

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, newbie problem

    Well then

    Qt Code:
    1. void Controller::setupsearchlistwindow(SearchListWindow* searchWindow)
    2. {
    3. connect( searchWindow, SIGNAL(searchButtonSelected()), this, SLOT(searchButtonSelected()));
    4. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void Controller::searchButtonSelected()
    2. {
    3. objectOfMethod->process();
    4. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  11. #11
    Join Date
    Jun 2014
    Posts
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, newbie problem

    Thanks for patience

    I write this code but doesn' work. I try with qDebug message.

    Main.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "searchlistwindow.h"
    3. #include <QApplication>
    4. #include "controller.hpp"
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9. MainWindow w;
    10. SearchListWindow x;
    11. Controller controller;
    12. controller.setupmainwindows(&w);
    13. controller.setupsearchlistwindow(&x);
    14. w.show();
    15.  
    16. return a.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 

    Controller.cpp
    Qt Code:
    1. void Controller::setupmainwindows(MainWindow *mainWindow)
    2. {
    3.  
    4. }
    5. void Controller::setupsearchlistwindow(SearchListWindow* searchWindow)
    6. {
    7. connect(searchWindow, SIGNAL(searchButtonSelected()), this, SLOT(searchButtonSelected()));
    8.  
    9. }
    10.  
    11. void Controller::searchButtonSelected()
    12. {
    13. qDebug()<<"Test";
    14. }
    To copy to clipboard, switch view to plain text mode 

    and show only text from on_pushButton_clicked
    Qt Code:
    1. void SearchListWindow::on_pushButton_clicked()
    2. {
    3. emit searchButtonSelected();
    4. qDebug() << "Search push button clicked";
    5. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by testQtowiec; 21st June 2014 at 11:15.

  12. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, newbie problem

    What is the return value of the connect call?

    Do you get any runtime warning?

    Cheers,
    _

  13. #13
    Join Date
    Jun 2014
    Posts
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, newbie problem

    I delete connect in setupmainwindows.

    0 warnings

    in mainWindow.cpp I create searchWindows
    Qt Code:
    1. void MainWindow::on_Button()
    2. {
    3. SearchListWindow* searchWindow = new SearchListWindow(this);
    4. searchWindow->show();
    5. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by testQtowiec; 21st June 2014 at 11:40.

  14. #14
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, newbie problem

    Well, that instance of SearchListWindow is not connected, is it?
    How do you expect the signal to reach the slot without it being connected?

    Cheers,
    _

  15. #15
    Join Date
    Jun 2014
    Posts
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, newbie problem

    ok, but I don't know how connect this istance.

  16. #16
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, newbie problem

    Well, since you have a method for doing that connect, one way to connect this instance of the dialog would be to pass it to that method.

    But since you create an instance of the SearchListWindow in main(), maybe you want to use that in Mainwindow instead of creating another one?

    Cheers,
    _

  17. #17
    Join Date
    Jun 2014
    Posts
    9
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, newbie problem

    Yes I want to use instance of SearchListWindows from MainWindow

  18. #18
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: signals and slots, newbie problem

    You want to use the ifirst nstance you created in main() inside Mainwindow, or use the second instance you created in Mainwindow:n_button?

    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 18th April 2013, 12:15
  2. Problem with Signals and Slots
    By Nayrb in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2012, 08:45
  3. Replies: 4
    Last Post: 21st March 2011, 03:38
  4. problem with signals/slots
    By vaas in forum Newbie
    Replies: 3
    Last Post: 2nd April 2010, 14:24
  5. Problem using SIGNALS/SLOTS
    By JimDaniel in forum Qt Programming
    Replies: 5
    Last Post: 10th September 2007, 04:59

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.