Results 1 to 20 of 24

Thread: Passing strings to SLOT function

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    May 2012
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Passing strings to SLOT function

    I'm not sure why I'm having an error saying that SIGNAL was not declared.

    Qt Code:
    1. mainwindow.cpp:14:78: error: macro "SIGNAL" passed 3 arguments, but takes just 1
    2. mainwindow.cpp: In constructor ‘MainWindow::MainWindow(QWidget*)’:
    3. mainwindow.cpp:14:16: error: ‘SIGNAL’ was not declared in this scope
    4. make: *** [mainwindow.o] Error 1
    To copy to clipboard, switch view to plain text mode 


    Here is my code

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_main.h"
    3. #include "socketthread.h"
    4. #include <QApplication>
    5.  
    6. using namespace std;
    7.  
    8. MainWindow::MainWindow(QWidget *parent) :
    9. QMainWindow(parent),
    10. ui(new Ui::MainWindow)
    11. {
    12. ui->setupUi(this);
    13. connect(this, SIGNAL(sendMessage(QString), SocketThread, SLOT(send(QString)));
    14. }
    15.  
    16. MainWindow::~MainWindow()
    17. {
    18. delete ui;
    19. }
    20.  
    21. void MainWindow::on_pushButton_clicked()
    22. {
    23. emit sendMessage("ABCD");
    24. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui
    7. {
    8. class MainWindow;
    9. }
    10.  
    11. class MainWindow : public QMainWindow {
    12. Q_OBJECT
    13.  
    14. public:
    15. MainWindow(QWidget *parent = 0);
    16. ~MainWindow();
    17.  
    18. signals:
    19. void sendMessage(QString message);
    20.  
    21. private slots:
    22. void on_pushButton_clicked();
    23.  
    24. private:
    25. Ui::MainWindow *ui;
    26.  
    27. };
    28.  
    29. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    socketthread.cpp
    Qt Code:
    1. void SocketThread::run()
    2. {
    3. .....
    4. .....
    5. string_in = send(); // not sure how to connect the Qstring value here
    6. .....
    7. .....
    8. }
    To copy to clipboard, switch view to plain text mode 

    socketthread.h
    Qt Code:
    1. #ifndef SOCKET_H
    2. #define SOCKET_H
    3. #include <QThread>
    4.  
    5. class SocketThread : public QThread
    6. {
    7. Q_OBJECT
    8.  
    9. public slots:
    10. void send(QString message);
    11.  
    12. private:
    13. void run();
    14. };
    15. #endif // SOCKET_H
    To copy to clipboard, switch view to plain text mode 
    Last edited by ashboi; 7th September 2013 at 13:32.

Similar Threads

  1. Passing argument to slot.
    By TCB13 in forum Newbie
    Replies: 2
    Last Post: 22nd February 2012, 19:52
  2. Passing data via signal/slot
    By gib in forum Qt Programming
    Replies: 4
    Last Post: 1st November 2010, 05:49
  3. Passing an integer to a slot
    By bizmopeen in forum Newbie
    Replies: 6
    Last Post: 30th October 2009, 09:51
  4. Passing QsqlRecords in a function
    By ambarish_singh in forum Qt Programming
    Replies: 7
    Last Post: 13th August 2009, 11:10
  5. passing arguments in SLOT
    By eleanor in forum Qt Programming
    Replies: 3
    Last Post: 3rd July 2008, 21:55

Tags for this Thread

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.