Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Declaration of function and use it

Declaration of function and use it

Scheduled Pinned Locked Moved Unsolved General and Desktop
93 Posts 4 Posters 58.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G gauravsharma0190
    13 Jul 2016, 11:22

    @jsulm
    Yes i did the same but error occurs.
    i couldnt find where is problem

    J Offline
    J Offline
    jsulm
    Lifetime Qt Champion
    wrote on 13 Jul 2016, 11:23 last edited by
    #12

    @gauravsharma0190 That's why I'm asking for the code! Without it I cannot find the problem as well.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gauravsharma0190
      wrote on 13 Jul 2016, 11:33 last edited by
      #13

      So please tell me what i send you sir.
      i give you my all the code .
      Now please tell me only that how to invoke code when i click the button

      J M 3 Replies Last reply 13 Jul 2016, 11:39
      0
      • G gauravsharma0190
        13 Jul 2016, 11:33

        So please tell me what i send you sir.
        i give you my all the code .
        Now please tell me only that how to invoke code when i click the button

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 13 Jul 2016, 11:39 last edited by
        #14

        @gauravsharma0190 I already said that: mainwindow.h and mainwindow.cpp
        I provided you a link where you can learn how signals and slots in Qt work, here it is again: http://doc.qt.io/qt-5.7/signalsandslots.html
        Please read it! Else you will not be able to use Qt much - signals/slots is one of the most important concepts in Qt.
        Short description: QPushButton has a signal clicked() (see http://doc.qt.io/qt-5/qabstractbutton.html#clicked). This signal is emitted when user presses the button. You need to connect a slot to that signal, then this slot will be called when you press the button.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • G gauravsharma0190
          13 Jul 2016, 11:33

          So please tell me what i send you sir.
          i give you my all the code .
          Now please tell me only that how to invoke code when i click the button

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 13 Jul 2016, 11:53 last edited by
          #15

          @gauravsharma0190 A small example application with a button:

          // main.cpp
          #include "mainwindow.h"
          #include <QApplication>
          
          int main(int argc, char *argv[])
          {
              QApplication a(argc, argv);
              MainWindow w;
              w.show();
          
              return a.exec();
          }
          
          // mainwindow.h
          #ifndef MAINWINDOW_H
          #define MAINWINDOW_H
          
          #include <QMainWindow>
          
          namespace Ui {
          class MainWindow;
          }
          
          class MainWindow : public QMainWindow
          {
              Q_OBJECT
          
          public:
              explicit MainWindow(QWidget *parent = 0);
              ~MainWindow();
          
          private slots:
              void doSomethingWhenButtonPressed(bool);
          
          private:
              Ui::MainWindow *ui;
          };
          
          #endif // MAINWINDOW_H
          
          // mainwindow.cpp
          #include "mainwindow.h"
          #include "ui_mainwindow.h"
          
          #include <QDebug>
          
          MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::MainWindow)
          {
              ui->setupUi(this);
          
              connect(ui->pushButton, SIGNAL(clicked(bool)), this, SLOT(doSomethingWhenButtonPressed(bool)));
          }
          
          MainWindow::~MainWindow()
          {
              delete ui;
          }
          
          void MainWindow::doSomethingWhenButtonPressed(bool)
          {
              qDebug() << "Button pressed!";
          }

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          G 1 Reply Last reply 14 Jul 2016, 06:43
          1
          • J jsulm
            13 Jul 2016, 11:53

            @gauravsharma0190 A small example application with a button:

            // main.cpp
            #include "mainwindow.h"
            #include <QApplication>
            
            int main(int argc, char *argv[])
            {
                QApplication a(argc, argv);
                MainWindow w;
                w.show();
            
                return a.exec();
            }
            
            // mainwindow.h
            #ifndef MAINWINDOW_H
            #define MAINWINDOW_H
            
            #include <QMainWindow>
            
            namespace Ui {
            class MainWindow;
            }
            
            class MainWindow : public QMainWindow
            {
                Q_OBJECT
            
            public:
                explicit MainWindow(QWidget *parent = 0);
                ~MainWindow();
            
            private slots:
                void doSomethingWhenButtonPressed(bool);
            
            private:
                Ui::MainWindow *ui;
            };
            
            #endif // MAINWINDOW_H
            
            // mainwindow.cpp
            #include "mainwindow.h"
            #include "ui_mainwindow.h"
            
            #include <QDebug>
            
            MainWindow::MainWindow(QWidget *parent) :
                QMainWindow(parent),
                ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
            
                connect(ui->pushButton, SIGNAL(clicked(bool)), this, SLOT(doSomethingWhenButtonPressed(bool)));
            }
            
            MainWindow::~MainWindow()
            {
                delete ui;
            }
            
            void MainWindow::doSomethingWhenButtonPressed(bool)
            {
                qDebug() << "Button pressed!";
            }
            G Offline
            G Offline
            gauravsharma0190
            wrote on 14 Jul 2016, 06:43 last edited by
            #16

            @jsulm
            i got it tht how to use push button.
            using connect i know it because i did it with my code.
            but i want to know how to declare and defination of function in qt and use these in pushbutton.
            Like we do in c as declare and defination of function and use it main()
            as in c++ declare and defination and use it in main function or classes.
            please give me a simple example or link.

            like

            J 1 Reply Last reply 14 Jul 2016, 06:49
            0
            • G gauravsharma0190
              14 Jul 2016, 06:43

              @jsulm
              i got it tht how to use push button.
              using connect i know it because i did it with my code.
              but i want to know how to declare and defination of function in qt and use these in pushbutton.
              Like we do in c as declare and defination of function and use it main()
              as in c++ declare and defination and use it in main function or classes.
              please give me a simple example or link.

              like

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 14 Jul 2016, 06:49 last edited by
              #17

              @gauravsharma0190 I don't understand the problem. Qt is not a programming language. You use C++ with qt. So you define and use your function/method as any other function/method in C++.
              I already gave you an example showing how to use a push button to execute a method when the button is clicked. Isn't that what you want to do?
              Please explain what is the problem! Maybe some code?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              G 1 Reply Last reply 14 Jul 2016, 10:16
              0
              • G gauravsharma0190
                13 Jul 2016, 11:33

                So please tell me what i send you sir.
                i give you my all the code .
                Now please tell me only that how to invoke code when i click the button

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 14 Jul 2016, 07:05 last edited by mrjj
                #18

                @gauravsharma0190

                Hi
                As @jsulm says, its a bit unclear what you ask.
                You can use functions just like you would in c, but in c++ gui program,
                normally main is the not the center of the application. QMainwindow is or some other class.
                Maybe this helps:

                //--------------------
                //std c program
                //--------------------
                void myfunc() {};
                
                void main() {
                  myfunc();
                }
                
                //--------------------
                //c++ function being a class member ( lives in class)
                //--------------------
                class Mainwindow {
                 public:
                  void myfunc();
                };
                (in cpp)
                Mainwindow::myfunc() {
                  //code
                }
                //--------------------
                //c++ with "outside" function ( non member function)
                //--------------------
                (in .h)
                void outsidefunc(); // define
                
                class Mainwindow {
                 public:
                  void myfunc();
                };
                (in cpp)
                
                void outsidefunc() { // implement
                }
                
                Mainwindow::myfunc() {
                  outsidefunc();
                }
                
                1 Reply Last reply
                1
                • G Offline
                  G Offline
                  gauravsharma0190
                  wrote on 14 Jul 2016, 07:15 last edited by
                  #19

                  Yes sir see i have a c code of opencv which process the image.
                  Now my problem is i want to use this code with qt as when button is pressed my push button calls the function of that C code in which main part of Process is defined.
                  Here is the C code.
                  #include "opencv2/imgproc/imgproc.hpp"
                  #include "opencv2/highgui/highgui.hpp"
                  #include <stdlib.h>
                  #include <stdio.h>

                  using namespace cv;

                  /// Global variables

                  Mat src, src_gray;
                  Mat dst, detected_edges;

                  int edgeThresh = 1;
                  int lowThreshold;
                  int const max_lowThreshold = 100;
                  int ratio = 3;
                  int kernel_size = 3;
                  char* window_name = "Edge Map";

                  /**

                  • @function CannyThreshold
                  • @brief Trackbar callback - Canny thresholds input with a ratio 1:3
                    /
                    void CannyThreshold(int, void
                    )
                    {
                    /// Reduce noise with a kernel 3x3
                    blur( src_gray, detected_edges, Size(3,3) );

                  /// Canny detector
                  Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );

                  /// Using Canny's output as a mask, we display our result
                  dst = Scalar::all(0);

                  src.copyTo( dst, detected_edges);
                  imshow( window_name, dst );
                  }

                  /** @function main /
                  int main( int argc, char
                  * argv )
                  {
                  /// Load an image
                  src = imread( argv[1] );

                  if( !src.data )
                  { return -1; }

                  /// Create a matrix of the same type and size as src (for dst)
                  dst.create( src.size(), src.type() );

                  /// Convert the image to grayscale
                  cvtColor( src, src_gray, CV_BGR2GRAY );

                  /// Create a window
                  namedWindow( window_name, CV_WINDOW_AUTOSIZE );

                  /// Create a Trackbar for user to enter threshold
                  createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold, CannyThreshold );

                  /// Show the image
                  CannyThreshold(0, 0);

                  /// Wait until user exit program by pressing a key
                  waitKey(0);

                  return 0;
                  }
                  Now i make a Push button Name Process_image in MainWindow.ui and connect to slot as clicked() by right clicking of mouse.
                  here comes the slot to mainwindow.cpp
                  void mainwidow::Process_image_clicke()
                  {
                  }
                  Now i don't understand how to make function of my C code and use it in Pusebutton.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 14 Jul 2016, 07:21 last edited by mrjj
                    #20

                    well you should make a pair of .h and .cpp files for the opencv stuff
                    lets call it myopenvc.h and myopenvc.cpp

                    in h. you can declare the function u want rest of program to use

                    void setupOPENVC();

                    and in .cpp

                    void setupOPENVC() {
                    // the code from the old c- main. !
                    src = imread( argv[1] );
                    xxxx
                    }

                    then in Mainwindow.cpp
                    #include "myopencv.h"

                    and now u can call your function
                    void mainwidow::Process_image_clicke()
                    {
                    setupOPENVC();
                    }

                    ps:
                    In event driven programs. ( like Qt)
                    stuff like
                    waitKey(0);
                    or FOREVER loops are not to be used as it
                    will freeze the program and it stops working.

                    G 1 Reply Last reply 14 Jul 2016, 10:10
                    1
                    • M mrjj
                      14 Jul 2016, 07:21

                      well you should make a pair of .h and .cpp files for the opencv stuff
                      lets call it myopenvc.h and myopenvc.cpp

                      in h. you can declare the function u want rest of program to use

                      void setupOPENVC();

                      and in .cpp

                      void setupOPENVC() {
                      // the code from the old c- main. !
                      src = imread( argv[1] );
                      xxxx
                      }

                      then in Mainwindow.cpp
                      #include "myopencv.h"

                      and now u can call your function
                      void mainwidow::Process_image_clicke()
                      {
                      setupOPENVC();
                      }

                      ps:
                      In event driven programs. ( like Qt)
                      stuff like
                      waitKey(0);
                      or FOREVER loops are not to be used as it
                      will freeze the program and it stops working.

                      G Offline
                      G Offline
                      gauravsharma0190
                      wrote on 14 Jul 2016, 10:10 last edited by
                      #21

                      @mrjj Hello i did it sir.
                      but error occurs.

                      1 Reply Last reply
                      0
                      • J jsulm
                        14 Jul 2016, 06:49

                        @gauravsharma0190 I don't understand the problem. Qt is not a programming language. You use C++ with qt. So you define and use your function/method as any other function/method in C++.
                        I already gave you an example showing how to use a push button to execute a method when the button is clicked. Isn't that what you want to do?
                        Please explain what is the problem! Maybe some code?

                        G Offline
                        G Offline
                        gauravsharma0190
                        wrote on 14 Jul 2016, 10:16 last edited by
                        #22

                        @jsulm Yes sir see i have a c code of opencv which process the image.
                        Now my problem is i want to use this code with qt as when button is pressed my push button calls the function of that C code in which main part of Process is defined.
                        Here is the C code.
                        #include "opencv2/imgproc/imgproc.hpp"
                        #include "opencv2/highgui/highgui.hpp"
                        #include <stdlib.h>
                        #include <stdio.h>

                        using namespace cv;

                        /// Global variables

                        Mat src, src_gray;
                        Mat dst, detected_edges;

                        int edgeThresh = 1;
                        int lowThreshold;
                        int const max_lowThreshold = 100;
                        int ratio = 3;
                        int kernel_size = 3;
                        char* window_name = "Edge Map";

                        /**

                        @function CannyThreshold
                        @brief Trackbar callback - Canny thresholds input with a ratio 1:3
                        /
                        void CannyThreshold(int, void)
                        {
                        /// Reduce noise with a kernel 3x3
                        blur( src_gray, detected_edges, Size(3,3) );
                        /// Canny detector
                        Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );

                        /// Using Canny's output as a mask, we display our result
                        dst = Scalar::all(0);

                        src.copyTo( dst, detected_edges);
                        imshow( window_name, dst );
                        }

                        /** @function main /
                        int main( int argc, char* argv )
                        {
                        /// Load an image
                        src = imread( argv[1] );

                        if( !src.data )
                        { return -1; }

                        /// Create a matrix of the same type and size as src (for dst)
                        dst.create( src.size(), src.type() );

                        /// Convert the image to grayscale
                        cvtColor( src, src_gray, CV_BGR2GRAY );

                        /// Create a window
                        namedWindow( window_name, CV_WINDOW_AUTOSIZE );

                        /// Create a Trackbar for user to enter threshold
                        createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold, CannyThreshold );

                        /// Show the image
                        CannyThreshold(0, 0);

                        /// Wait until user exit program by pressing a key
                        waitKey(0);

                        return 0;
                        }
                        Now i make a Push button Name Process_image in MainWindow.ui and connect to slot as clicked() by right clicking of mouse.
                        here comes the slot to mainwindow.cpp
                        void mainwidow::Process_image_clicke()
                        {
                        }
                        Now i don't understand how to make function of my C code and use it in Pusebutton.

                        J 1 Reply Last reply 14 Jul 2016, 10:20
                        0
                        • G gauravsharma0190
                          14 Jul 2016, 10:16

                          @jsulm Yes sir see i have a c code of opencv which process the image.
                          Now my problem is i want to use this code with qt as when button is pressed my push button calls the function of that C code in which main part of Process is defined.
                          Here is the C code.
                          #include "opencv2/imgproc/imgproc.hpp"
                          #include "opencv2/highgui/highgui.hpp"
                          #include <stdlib.h>
                          #include <stdio.h>

                          using namespace cv;

                          /// Global variables

                          Mat src, src_gray;
                          Mat dst, detected_edges;

                          int edgeThresh = 1;
                          int lowThreshold;
                          int const max_lowThreshold = 100;
                          int ratio = 3;
                          int kernel_size = 3;
                          char* window_name = "Edge Map";

                          /**

                          @function CannyThreshold
                          @brief Trackbar callback - Canny thresholds input with a ratio 1:3
                          /
                          void CannyThreshold(int, void)
                          {
                          /// Reduce noise with a kernel 3x3
                          blur( src_gray, detected_edges, Size(3,3) );
                          /// Canny detector
                          Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );

                          /// Using Canny's output as a mask, we display our result
                          dst = Scalar::all(0);

                          src.copyTo( dst, detected_edges);
                          imshow( window_name, dst );
                          }

                          /** @function main /
                          int main( int argc, char* argv )
                          {
                          /// Load an image
                          src = imread( argv[1] );

                          if( !src.data )
                          { return -1; }

                          /// Create a matrix of the same type and size as src (for dst)
                          dst.create( src.size(), src.type() );

                          /// Convert the image to grayscale
                          cvtColor( src, src_gray, CV_BGR2GRAY );

                          /// Create a window
                          namedWindow( window_name, CV_WINDOW_AUTOSIZE );

                          /// Create a Trackbar for user to enter threshold
                          createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold, CannyThreshold );

                          /// Show the image
                          CannyThreshold(0, 0);

                          /// Wait until user exit program by pressing a key
                          waitKey(0);

                          return 0;
                          }
                          Now i make a Push button Name Process_image in MainWindow.ui and connect to slot as clicked() by right clicking of mouse.
                          here comes the slot to mainwindow.cpp
                          void mainwidow::Process_image_clicke()
                          {
                          }
                          Now i don't understand how to make function of my C code and use it in Pusebutton.

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 14 Jul 2016, 10:20 last edited by
                          #23

                          @gauravsharma0190 Well, you can put that C code in

                          void mainwidow::Process_image_clicke()
                          {
                              // Put C code here
                          }
                          

                          But I'm not sure whether you should remove waitKey(0); as it could be problematic in a Qt program.

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          G 1 Reply Last reply 14 Jul 2016, 11:32
                          2
                          • J jsulm
                            14 Jul 2016, 10:20

                            @gauravsharma0190 Well, you can put that C code in

                            void mainwidow::Process_image_clicke()
                            {
                                // Put C code here
                            }
                            

                            But I'm not sure whether you should remove waitKey(0); as it could be problematic in a Qt program.

                            G Offline
                            G Offline
                            gauravsharma0190
                            wrote on 14 Jul 2016, 11:32 last edited by
                            #24

                            @jsulm
                            i put it into Process_image_click()
                            {
                            //code
                            }
                            but error occurs.
                            as ontrackball function not declare

                            J 1 Reply Last reply 14 Jul 2016, 11:38
                            0
                            • G gauravsharma0190
                              14 Jul 2016, 11:32

                              @jsulm
                              i put it into Process_image_click()
                              {
                              //code
                              }
                              but error occurs.
                              as ontrackball function not declare

                              J Offline
                              J Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 14 Jul 2016, 11:38 last edited by
                              #25

                              @gauravsharma0190 What is ontrackball? Where is it declared? Do you have to include a header file where it is declared?

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              G 1 Reply Last reply 15 Jul 2016, 06:47
                              0
                              • G Offline
                                G Offline
                                gauravsharma0190
                                wrote on 15 Jul 2016, 06:38 last edited by
                                #26

                                Yes it is function which is declare in the Opencv C code.
                                Here is the function.
                                @brief Trackbar callback - Canny thresholds input with a ratio 1:3
                                /
                                void onTrackball(int, void)
                                {
                                /// Reduce noise with a kernel 3x3
                                blur( src_gray, detected_edges, Size(3,3) );
                                /// Canny detector
                                Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );

                                /// Using Canny's output as a mask, we display our result
                                dst = Scalar::all(0);

                                src.copyTo( dst, detected_edges);
                                imshow( window_name, dst );
                                }

                                1 Reply Last reply
                                0
                                • J jsulm
                                  14 Jul 2016, 11:38

                                  @gauravsharma0190 What is ontrackball? Where is it declared? Do you have to include a header file where it is declared?

                                  G Offline
                                  G Offline
                                  gauravsharma0190
                                  wrote on 15 Jul 2016, 06:47 last edited by
                                  #27

                                  @jsulm Yes it is function which is declare in the Opencv C code.
                                  Here is the function.
                                  @brief Trackbar callback - Canny thresholds input with a ratio 1:3
                                  /
                                  void onTrackball(int, void)
                                  {
                                  /// Reduce noise with a kernel 3x3
                                  blur( src_gray, detected_edges, Size(3,3) );
                                  /// Canny detector
                                  Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );

                                  /// Using Canny's output as a mask, we display our result
                                  dst = Scalar::all(0);

                                  src.copyTo( dst, detected_edges);
                                  imshow( window_name, dst );
                                  }

                                  less than a minute ago

                                  J 1 Reply Last reply 15 Jul 2016, 06:50
                                  0
                                  • G gauravsharma0190
                                    15 Jul 2016, 06:47

                                    @jsulm Yes it is function which is declare in the Opencv C code.
                                    Here is the function.
                                    @brief Trackbar callback - Canny thresholds input with a ratio 1:3
                                    /
                                    void onTrackball(int, void)
                                    {
                                    /// Reduce noise with a kernel 3x3
                                    blur( src_gray, detected_edges, Size(3,3) );
                                    /// Canny detector
                                    Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );

                                    /// Using Canny's output as a mask, we display our result
                                    dst = Scalar::all(0);

                                    src.copyTo( dst, detected_edges);
                                    imshow( window_name, dst );
                                    }

                                    less than a minute ago

                                    J Offline
                                    J Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on 15 Jul 2016, 06:50 last edited by
                                    #28

                                    @gauravsharma0190 Where is this function declared? In which header file? "function not declared" means the function is not known. You have to make it visible including the header file. It is the same story as in C.

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    G 2 Replies Last reply 15 Jul 2016, 07:11
                                    0
                                    • J jsulm
                                      15 Jul 2016, 06:50

                                      @gauravsharma0190 Where is this function declared? In which header file? "function not declared" means the function is not known. You have to make it visible including the header file. It is the same story as in C.

                                      G Offline
                                      G Offline
                                      gauravsharma0190
                                      wrote on 15 Jul 2016, 07:11 last edited by
                                      #29

                                      @jsulm i Declare it in mainwindow.h
                                      file as void onTrackball.
                                      and i will send you all my code which i did .

                                      1 Reply Last reply
                                      0
                                      • J jsulm
                                        15 Jul 2016, 06:50

                                        @gauravsharma0190 Where is this function declared? In which header file? "function not declared" means the function is not known. You have to make it visible including the header file. It is the same story as in C.

                                        G Offline
                                        G Offline
                                        gauravsharma0190
                                        wrote on 18 Jul 2016, 05:35 last edited by
                                        #30

                                        @jsulm
                                        Here i am sending you my all code.
                                        **

                                        • /////main.cpp///**
                                          #include "mainwindow.h"
                                          #include <QApplication>
                                          #include<QSplashScreen>
                                          #include<QTimer>
                                          #include<opencv2/highgui/highgui.hpp>
                                          #include<opencv2/core/core.hpp>
                                          #include<opencv2/opencv.hpp>
                                          using namespace cv;
                                          using namespace std;
                                          int main(int argc, char *argv[])
                                          {

                                          QApplication a(argc, argv);
                                          QSplashScreen *splash =new QSplashScreen;
                                          splash->setPixmap(QPixmap("/home/pi/Desktop/ceeri1.jpg"));
                                          splash->show();

                                          MainWindow w;
                                          QTimer::singleShot(3500,splash,SLOT(close()));

                                          QTimer::singleShot(3500,&w,SLOT(show()));

                                          //w.show();

                                          return a.exec();
                                          }
                                          ////mainwindow.h
                                          #ifndef MAINWINDOW_H
                                          #define MAINWINDOW_H

                                        #include <QMainWindow>
                                        //using namespace cv;
                                        namespace Ui {
                                        class MainWindow;
                                        }

                                        class MainWindow : public QMainWindow
                                        {
                                        Q_OBJECT

                                        public:
                                        explicit MainWindow(QWidget *parent = 0);
                                        ~MainWindow();

                                        private slots:
                                        void showTime();

                                        void on_pushButton_5_clicked();
                                        

                                        void onTrackball_clicked(int,void*);

                                        private:
                                        Ui::MainWindow *ui;
                                        };

                                        #endif // MAINWINDOW_H
                                        ///mainwindow.c

                                        #include "mainwindow.h"
                                        #include "ui_mainwindow.h"
                                        #include<opencv2/opencv.hpp>
                                        #include <opencv2/highgui/highgui.hpp>
                                        #include <opencv2/core/core.hpp>
                                        #include<QFileDialog>
                                        #include<QMessageBox>
                                        #include <iostream>
                                        #include <string>
                                        #include <fstream>
                                        #include<time.h>
                                        #include<QTimer>
                                        #include<QDateTime>
                                        using namespace cv;
                                        using namespace std;
                                        MainWindow::MainWindow(QWidget *parent) :
                                        QMainWindow(parent),
                                        ui(new Ui::MainWindow)
                                        {
                                        ui->setupUi(this);
                                        QTimer *timer=new QTimer(this);
                                        connect(timer,SIGNAL(timeout()),this,SLOT(showTime()));
                                        timer->start();
                                        QDateTime dateTime=QDateTime::currentDateTime();
                                        QString datetimetext=dateTime.toString();
                                        ui->DateTime->setText(datetimetext);

                                        }
                                        ////////Time///////////////
                                        void MainWindow:: showTime()
                                        {
                                        QTime time=QTime::currentTime();
                                        QString time_text=time.toString("hh : mm : ss");
                                        if((time.second() % 2)==0)
                                        {
                                        time_text[3] =' ';
                                        time_text[8] =' ';
                                        }
                                        ui->Digital->setText(time_text);

                                        }

                                        MainWindow::~MainWindow()
                                        {
                                        delete ui;
                                        }

                                        void MainWindow::on_pushButton_4_clicked()
                                        {

                                        }

                                        void MainWindow::on_pushButton_5_clicked()
                                        {
                                        QString filename=QFileDialog::getOpenFileName(
                                        this,
                                        tr("Open file") ,
                                        "/home/pi/Desktop",
                                        tr("All files(*.png *.jpg)"));

                                        QMessageBox::information(this,tr("Filename"),filename);
                                        if(QString::compare(filename,QString())!=0)
                                        {
                                            QImage image;
                                            bool valid=image.load(filename);
                                            if(valid)
                                            {
                                                image=image.scaledToWidth(ui->Picture->width(),Qt::SmoothTransformation);
                                                ui->Picture->setPixmap(QPixmap::fromImage(image));
                                        
                                            }
                                        

                                        void MainWindow::onTrackball_clicked(int,void*)
                                        {
                                        //Here wite the all function//
                                        ///Now how to put this code in this.

                                        ////////This is the code i have to input in this push button////
                                        Mat src, src_gray;
                                        Mat dst, detected_edges;

                                        int edgeThresh = 1;
                                        int lowThreshold;
                                        int const max_lowThreshold = 100;
                                        int ratio = 3;
                                        int kernel_size = 3;
                                        char* window_name = "Edge Map";

                                        /**

                                        @function CannyThreshold
                                        @brief Trackbar callback - Canny thresholds input with a ratio 1:3
                                        /
                                        void CannyThreshold(int, void)
                                        {
                                        /// Reduce noise with a kernel 3x3
                                        blur( src_gray, detected_edges, Size(3,3) );
                                        /// Canny detector
                                        Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );

                                        /// Using Canny's output as a mask, we display our result
                                        dst = Scalar::all(0);

                                        src.copyTo( dst, detected_edges);
                                        imshow( window_name, dst );
                                        }

                                        /** @function main /
                                        int main( int argc, char* argv )
                                        {
                                        /// Load an image
                                        src = imread( argv[1] );

                                        if( !src.data )
                                        { return -1; }

                                        /// Create a matrix of the same type and size as src (for dst)
                                        dst.create( src.size(), src.type() );

                                        /// Convert the image to grayscale
                                        cvtColor( src, src_gray, CV_BGR2GRAY );

                                        /// Create a window
                                        namedWindow( window_name, CV_WINDOW_AUTOSIZE );

                                        /// Create a Trackbar for user to enter threshold
                                        createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold, CannyThreshold );

                                        /// Show the image
                                        CannyThreshold(0, 0);

                                        /// Wait until user exit program by pressing a key
                                        waitKey(0);

                                        return 0;
                                        }

                                        }
                                        }
                                        
                                        1 Reply Last reply
                                        0
                                        • J Offline
                                          J Offline
                                          jsulm
                                          Lifetime Qt Champion
                                          wrote on 18 Jul 2016, 06:06 last edited by
                                          #31

                                          Sorry, but the code you posted is invalid C/C++! First of all: why do you have 2 main functions?
                                          Why did you put other functions inside void MainWindow::onTrackball_clicked(int,void*)? This is not going to compile and I'm not going to fix it for you. How familiar are you actually with C/C++?
                                          What you have to do is: do not put the C function definitions inside void MainWindow::onTrackball_clicked(int,void*), instead put them inside another source code file and header, include the header file in MainWindow and then call the functions in void MainWindow::onTrackball_clicked(int,void*). As an alternative you can have those C functions in MainWindow.cpp but not inside void MainWindow::onTrackball_clicked(int,void*) !

                                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          G 1 Reply Last reply 18 Jul 2016, 06:16
                                          1

                                          21/93

                                          14 Jul 2016, 10:10

                                          topic:navigator.unread, 72
                                          • Login

                                          • Login or register to search.
                                          21 out of 93
                                          • First post
                                            21/93
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved