Results 1 to 4 of 4

Thread: Not able to access functions of MainWindow functions from a mainwindow.cpp

  1. #1
    Join Date
    Dec 2016
    Posts
    2
    Platforms
    Windows

    Default Not able to access functions of MainWindow functions from a mainwindow.cpp

    I have a MainWindow class setup using Qt in Visual Studio. In the mainwindow.cpp file I have created a thread using pthread called 'solder_thread' which when created calls another function called 'perform_solder'. Inside this 'perform_solder', I am trying to access functions and variables declared in the MainWindow class, but I get an error message which says 'IntelliSense: identifier "move_stage_solder" is undefined'


    mainwindow.cpp:


    #include "mainwindow.h"

    void * perform_solder(void * arg);

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
    {

    connect(ui->pb_feeder, SIGNAL(clicked()), SLOT(enable_feeder_arduino()));

    }

    void MainWindow::enable_feeder_arduino(){

    pthread_t solder_thread;

    if (pthread_create(&solder_thread, NULL, &perform_solder, NULL)){
    ui->status_message->setText("Error in creating the serial communication thread");
    exit(-1);
    }

    }

    void MainWindow::move_stage_solder(double xpos, double ypos){

    /*Do something*/

    }


    void * perform_solder(void * arg){

    move_stage_solder(0,0); /*This is where the error shows up*/

    }

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Not able to access functions of MainWindow functions from a mainwindow.cpp

    In your code there is no function move_stage_solder. You have only method MainWindow::move_stage_solder. Fundamentals of C ++ unrelated to Qt.

  3. #3
    Join Date
    Dec 2016
    Posts
    2
    Platforms
    Windows

    Default Re: Not able to access functions of MainWindow functions from a mainwindow.cpp

    Yeah, but I want to access the move_stage_solder member function of the MainWindow class from inside perform_solder. Can you help me with that?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Not able to access functions of MainWindow functions from a mainwindow.cpp

    As was said, this is basic C++. To access a non-static method for any class, you need a pointer or reference to an instance of that class. So you need find a way to get a pointer to your MainWindow instance so that it is accessible from within the scope of perform_solder().

    Hint: Look at using QThread instead of pthread. You could keep a pointer to your MainWindow class instance as a member variable of your worker thread class.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 9
    Last Post: 31st May 2014, 22:52
  2. Refresh the mainwindow / functions called in the main loop
    By valerianst in forum Qt Programming
    Replies: 7
    Last Post: 2nd October 2013, 15:57
  3. Access to custom widget functions in a QGraphicsScene
    By meazza in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2011, 10:21
  4. Replies: 1
    Last Post: 9th January 2011, 08:20
  5. Replies: 2
    Last Post: 7th July 2010, 01:14

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