Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. How to run a C++ code in Qt?
Forum Update on Monday, May 27th 2025

How to run a C++ code in Qt?

Scheduled Pinned Locked Moved Installation and Deployment
123 Posts 5 Posters 108.7k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #47

    Because para returns a double and not a string.

    You should use QString::number(para(i,0))

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    RelaR 1 Reply Last reply
    0
    • SGaistS SGaist

      Because para returns a double and not a string.

      You should use QString::number(para(i,0))

      RelaR Offline
      RelaR Offline
      Rela
      wrote on last edited by Rela
      #48

      @SGaist
      This code in "main.cpp" outputs the area and prime of a circle in which QString::number(); is used to return float.

      #include "mainwindow.h"
      #include <QApplication>
      
      #include <QString>
      #include <QHBoxLayout>
      #include <QLabel>
      #include <QWidget>
      
      #include "stdafx.h"
      #include <iostream>
      #include <iomanip>
      using namespace std;
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          int radius = 3; //radius of circle
              float square; //area of circle
              float edge; //perimeter of circle
           square = 3.14 * radius*radius;
           edge = 2 * 3.14 *radius;
      
              //cout << "Circle are= " << area << endl;
              //cout << "Circle perimeter= " << perime;
      
              // Show area
              QString area = QString::number(square);
              QLabel* arlabel=new QLabel(area);
              // create horizontal layout
              arlabel->setAlignment(Qt::AlignCenter);
              QHBoxLayout* arlayout=new QHBoxLayout;
              // and add label to it
              arlayout->addWidget(arlabel);
              QWidget* arwidget=new QWidget;
              // set layout to widget
              arwidget->setLayout(arlayout);
              arwidget->show();
      
              // Show perime
              QString perime = QString::number(edge);
              QLabel* pelabel=new QLabel(perime);
              pelabel->setAlignment(Qt::AlignCenter);
              // create horizontal layout
              QHBoxLayout* pelayout=new QHBoxLayout;
              // and add label to it
              pelayout->addWidget(pelabel);
              QWidget* pewidget=new QWidget;
              // set layout to widget
              pewidget->setLayout(pelayout);
              pewidget->show();
          //MainWindow w;
          //w.show();
          return a.exec();
      }
      
      

      I created two "QLabel" in "Mainwindow.ui", but it opens two separate "Mainwindow.ui" and shows area and prime in each of them. But I want to have both on one "Mainwindow.ui".

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #49

        No, currently it shows two widgets: arwidget and pewidget.

        MainWindow.ui is innocent here since you don't even show MainWindow.

        If you only want to show one widget, create a QWidget, put a layout on it and add arwidget and pewidget to it. You don't even need MainWindow.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        RelaR 1 Reply Last reply
        0
        • SGaistS SGaist

          No, currently it shows two widgets: arwidget and pewidget.

          MainWindow.ui is innocent here since you don't even show MainWindow.

          If you only want to show one widget, create a QWidget, put a layout on it and add arwidget and pewidget to it. You don't even need MainWindow.

          RelaR Offline
          RelaR Offline
          Rela
          wrote on last edited by Rela
          #50

          @SGaist
          Hi, last week I created one widget and it worked. Today, I was goign to run it again, but the files format has changed. I think MSV was updated. First time MVS 2015 gave error "Severity Code Description Project File Line Suppression State Error Solution is not saved. Please save your solution before managing NuGet packages. 0".
          Should I click on Restore NuGet Packages?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #51

            I don't see why not.

            Note that your link is pointing to an invalid page

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            RelaR 1 Reply Last reply
            0
            • SGaistS SGaist

              I don't see why not.

              Note that your link is pointing to an invalid page

              RelaR Offline
              RelaR Offline
              Rela
              wrote on last edited by Rela
              #52

              @SGaist
              The MVS 2015 was updated automatically and after that it and Qt are not working anymore.
              First it gave error "...Please save your solution before managing NuGet packages". After that "the project file was unloaded". But when I tried other projects the error changed to "Failed to locate: "CL.exe. The system cannot find the file specified". I tried to install some components VS 2015: "Control Panel > Programs >Programs and Features > Microsoft Visual Studio > 'modify' > Visual C++ components and install", but it shows this window: here

              1 Reply Last reply
              0
              • jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #53

                Did you try the first option in this window?

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

                RelaR 1 Reply Last reply
                0
                • jsulmJ jsulm

                  Did you try the first option in this window?

                  RelaR Offline
                  RelaR Offline
                  Rela
                  wrote on last edited by
                  #54

                  @jsulm
                  Yes, it worked and now MSVC 2015 is working, but not Qt. 5.5.
                  It gives error "Qt Creator needs a compiler set up to build. Configure a compiler in the kit options." in "Issues and in "Complie Output" the error "Configuration is faulty. Check the Issues view for details. Error while building/deploying project Circle2 (kit: Desktop Qt 5.5.1 MSVC2013 64bit) When executing step "Make". "

                  I installed "standalone SDK" from here here Downloaded and a folder "Windows kits" was built in the same folder. I copied it in "Visual studio 14" folder, and run the Qt again, but this is Build & Run. No active "Desktop Qt5.5. MCVS 2013 64 bit".

                  I dont know what the problem is? The kit should be MCVs 2105?

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #55

                    I didn't realize… You changed Visual Studio's version in between. On Windows you can't mix and match compilers and libraries, Visual Studio's compilers are not compatible one with the other. So since you have the MSVC2013 Qt package, you have to use Visual Studio 2013 with it.

                    If you want to use Visual Studio 2015, you can either build Qt yourself, or go with the 5.6 beta which has VS2015 packages.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    RelaR 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      I didn't realize… You changed Visual Studio's version in between. On Windows you can't mix and match compilers and libraries, Visual Studio's compilers are not compatible one with the other. So since you have the MSVC2013 Qt package, you have to use Visual Studio 2013 with it.

                      If you want to use Visual Studio 2015, you can either build Qt yourself, or go with the 5.6 beta which has VS2015 packages.

                      RelaR Offline
                      RelaR Offline
                      Rela
                      wrote on last edited by
                      #56

                      @SGaist said:
                      Thanks, which one do you recommend? I spent a lot of time on lunching and problem with running my programs until now because of components and compilers. If I uninstall 5.5 and install 6.5. beta, does Qt 6.5. work conveniently with Qt5.5. projects?

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #57

                        You're too much in the future ;) It's 5.6

                        No problem using Qt 5.6 for project started with 5.5. Forward compatibility is one of Qt's guaranties.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        RelaR 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          You're too much in the future ;) It's 5.6

                          No problem using Qt 5.6 for project started with 5.5. Forward compatibility is one of Qt's guaranties.

                          RelaR Offline
                          RelaR Offline
                          Rela
                          wrote on last edited by
                          #58

                          @SGaist
                          I was going to uninstall it by opening "Maintenancetool.exe" > "Remove all components" but it gives this error in 92%...

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #59

                            Unusual, but why not just update ?

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            RelaR 1 Reply Last reply
                            0
                            • SGaistS SGaist

                              Unusual, but why not just update ?

                              RelaR Offline
                              RelaR Offline
                              Rela
                              wrote on last edited by
                              #60

                              @SGaist
                              I was going to work with Qt 5.6 beta with MVS2015. To have Qt 5.6 beta can I just update Qt 5.5? I clicked on update components in "Maintenancetool.exe" , is this the component I need?

                              1 Reply Last reply
                              1
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #61

                                No, that's Qt Creator. It's the IDE.

                                IIRC, the 5.6 beta installer is available through your Qt Account page

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                RelaR 1 Reply Last reply
                                0
                                • SGaistS SGaist

                                  No, that's Qt Creator. It's the IDE.

                                  IIRC, the 5.6 beta installer is available through your Qt Account page

                                  RelaR Offline
                                  RelaR Offline
                                  Rela
                                  wrote on last edited by
                                  #62

                                  @SGaist
                                  If you mean through this link, the Qt5.5 should not be uninstalled first?

                                  1 Reply Last reply
                                  1
                                  • SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #63

                                    There's also that link indeed. Since it's an offline installer, I don't remember whether it will overwrite the Qt folder or not

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    RelaR 1 Reply Last reply
                                    0
                                    • SGaistS SGaist

                                      There's also that link indeed. Since it's an offline installer, I don't remember whether it will overwrite the Qt folder or not

                                      RelaR Offline
                                      RelaR Offline
                                      Rela
                                      wrote on last edited by
                                      #64

                                      @SGaist
                                      Is the installation way different from Qt5.5? Why does Qt5.6 give this error, while I installed Qt5.5 in the same folder?

                                      1 Reply Last reply
                                      0
                                      • SGaistS Offline
                                        SGaistS Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #65

                                        Don't put Qt in a path with white spaces, that will save you much trouble.

                                        Interested in AI ? www.idiap.ch
                                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        RelaR 1 Reply Last reply
                                        0
                                        • SGaistS SGaist

                                          Don't put Qt in a path with white spaces, that will save you much trouble.

                                          RelaR Offline
                                          RelaR Offline
                                          Rela
                                          wrote on last edited by
                                          #66

                                          @SGaist
                                          If you mean "program files'' it was the same folder I installed previous Qt5.5 and didnt give any message. By default Qt5.6 beta selects the C drive to install.

                                          1 Reply Last reply
                                          0

                                          • Login

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