Error #1 - move the declaration of your slot method (onCalculateClicked()) to the "private slots:" section of the MainWIndow class definition.

Remaining errors all stem from the fact that "lineEditA", etc. are *not* member variables of your MainWindow class, but are member of the Ui::MainWindow class. This is a class automatically created by Qt's MOC (metaobject compiler) from your .ui file. It lives in the Ui namespace, which is why it is referenced as "Ui::MainWindow". Your own MainWindow constructor creates an instance of this Ui class (line 8 of mainwindow.cpp) and then initializes it (setupUi()) in the body of the constructor.

Since all of the widget variables defined in your .ui file are public member variables of the Ui::MainWindow class, so to retrieve them from code in MainWindow, you have to go through the pointer to the Ui instance:

ui->lineEditA->text(), etc.

It is a good habit to learn to embed your child widgets in a layout of some sort so they will behave properly on resize. Your centralWidget doesn't use a layout, and you've hard-coded all of the child widget positions within it. While this may work in this case, it isn't good practice. It is good to get into the habit of putting a layout into every custom widget so that good things happen on resize, change of font, whatever.

In this case, I would add a grid layout, and use horizontal and vertical spacers to push things into place. Here's your mainwindow.ui reworked with a grid layout and spacers:

Qt Code:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <ui version="4.0">
  3. <class>MainWindow</class>
  4. <widget class="QMainWindow" name="MainWindow">
  5. <property name="geometry">
  6. <rect>
  7. <x>0</x>
  8. <y>0</y>
  9. <width>445</width>
  10. <height>203</height>
  11. </rect>
  12. </property>
  13. <property name="windowTitle">
  14. <string>MainWindow</string>
  15. </property>
  16. <widget class="QWidget" name="centralWidget">
  17. <layout class="QGridLayout" name="gridLayout">
  18. <item row="0" column="5">
  19. <spacer name="horizontalSpacer">
  20. <property name="orientation">
  21. <enum>Qt::Horizontal</enum>
  22. </property>
  23. <property name="sizeHint" stdset="0">
  24. <size>
  25. <width>40</width>
  26. <height>20</height>
  27. </size>
  28. </property>
  29. </spacer>
  30. </item>
  31. <item row="0" column="4">
  32. <widget class="QLineEdit" name="lineEditSum"/>
  33. </item>
  34. <item row="1" column="2">
  35. <widget class="QToolButton" name="calculateButton">
  36. <property name="text">
  37. <string> Calculate</string>
  38. </property>
  39. </widget>
  40. </item>
  41. <item row="2" column="2">
  42. <spacer name="verticalSpacer">
  43. <property name="orientation">
  44. <enum>Qt::Vertical</enum>
  45. </property>
  46. <property name="sizeHint" stdset="0">
  47. <size>
  48. <width>20</width>
  49. <height>40</height>
  50. </size>
  51. </property>
  52. </spacer>
  53. </item>
  54. <item row="0" column="0">
  55. <widget class="QLineEdit" name="lineEditA"/>
  56. </item>
  57. <item row="0" column="1">
  58. <widget class="QLabel" name="label">
  59. <property name="text">
  60. <string>-</string>
  61. </property>
  62. </widget>
  63. </item>
  64. <item row="0" column="3">
  65. <widget class="QLabel" name="label_2">
  66. <property name="text">
  67. <string>=</string>
  68. </property>
  69. </widget>
  70. </item>
  71. <item row="0" column="2">
  72. <widget class="QLineEdit" name="lineEditB"/>
  73. </item>
  74. </layout>
  75. </widget>
  76. <widget class="QMenuBar" name="menuBar">
  77. <property name="geometry">
  78. <rect>
  79. <x>0</x>
  80. <y>0</y>
  81. <width>445</width>
  82. <height>26</height>
  83. </rect>
  84. </property>
  85. </widget>
  86. <widget class="QToolBar" name="mainToolBar">
  87. <attribute name="toolBarArea">
  88. <enum>TopToolBarArea</enum>
  89. </attribute>
  90. <attribute name="toolBarBreak">
  91. <bool>false</bool>
  92. </attribute>
  93. </widget>
  94. <widget class="QStatusBar" name="statusBar"/>
  95. </widget>
  96. <layoutdefault spacing="6" margin="11"/>
  97. <resources/>
  98. <connections/>
  99. </ui>
To copy to clipboard, switch view to plain text mode 

As you expand on this in Qt Designer, you add new widgets to the grid layout by clicking and dragging from Designer's "Widget Box" onto the form. The place where the widget will end up when you drop it will be highlighted by a red box (if you add it to an empty box in the grid) or a horizontal or vertical blue line if dropping it will expand the grid to add a new row or column of cells.