Qt creator- class does not name a type - qt5

I using qt creator 3.0.1 while building it shows MainWindow has not been declared
I tried changing order of #include statements but no luck.
code that gives error in function insert and display:
#ifndef WEATHER_H
#define WEATHER_H
#include "node.h"
#include "weather.h"
#include "mainwindow.h"
#define NODE_H
class Weather
{
private:
Node *head;
public:
Weather();
void insert(MainWindow *);
void disp(MainWindow *);
};
#endif // WEATHER_H
my other header files:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "weather.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
Weather *w;
};
#endif // MAINWINDOW_H
node.h
#ifndef NODE_H
#define NODE_H
class Node
{
private:
some variables
friend class Weather;
public:
Node();
};
#endif // NODE_H
weather.h:

Related

Using 'override' keyword

My code gives the following error:
error C3668: 'B::getData': method with override specifier 'override' did not override any base class methods
#include<iostream>
#include <tuple>
using namespace std;
class A {
public:
int a;
int getData() {
return a;
}
};
class B : public A {
public:
int b;
B() {
b = 100;
}
int getData() override {
return b;
}
};
int main() {
B b;
cout << b.getData() << endl;
}
Why does error occurs and how can I resolve it ??
Your original function in A has to be virtual to be overrided.
class A {
public:
int a;
virtual int getData() {
return a;
}
};
More info about override is here. And related: info on virtual and final

How to access form elements from another classes?

This my first time trying to create windows application using vs clr and i'm trying to implement it on my existing cpp project which i almost finished but the main problem that i'm facing is the i can't access the functions of myForm.h (buttons , text box , etc..) from my main source.cpp , any help would be appreciated and thanks
MyForm.h
#pragma once
namespace Project2 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::RichTextBox^ richTextBox1;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(104, 177);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// richTextBox1
//
this->richTextBox1->Location = System::Drawing::Point(47, 36);
this->richTextBox1->Name = L"richTextBox1";
this->richTextBox1->Size = System::Drawing::Size(208, 135);
this->richTextBox1->TabIndex = 1;
this->richTextBox1->Text = L"";
this->richTextBox1->TextChanged += gcnew System::EventHandler(this, &MyForm::richTextBox1_TextChanged);
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(282, 253);
this->Controls->Add(this->richTextBox1);
this->Controls->Add(this->button1);
this->Name = L"MyForm";
this->Text = L"MyForm";
this->ResumeLayout(false);
}
#pragma endregion
public: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {};
public: System::Void richTextBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {}
};
}
Main.c
#include <iostream>
#include <fstream>
#include <sstream>
#include <locale>
#include <string>
#include<vector>
#include <time.h>
#include "MyForm.h"
using namespace std;
using namespace System;
[STAThread]
int main()
{
System::Windows::Forms::Application::Run(gcnew Project2::MyForm());
MyForm F; \\ can't create an object of MyForm class
F.richtextbox->AppendText("Hello world"); \\ here is the confusing part
System::Windows::Forms::Application::Run(gcnew Project2::MyForm());
return 0;
}

Singleton getinstance() method with void as return type

greetings.
I wrote the singleton class as shown below.
#include <iostream>
using namespace std;
class Singleton
{
private:
static bool inst;
static Singleton * ptr;
Singleton()
{
cout<<"Singleton Private Constructor is called"<<endl;
}
public:
static Singleton * Create_Instance()
{
if(!inst)
{
ptr = new Singleton();
inst = true;
cout<<"New instance is created"<<endl;
}
return ptr;
}
};
bool Singleton::inst = false;
Singleton * Singleton::ptr = NULL;
int main()
{
Singleton * point = Singleton::Create_Instance();
return 0;
}
Here the Singleton instance is returned to main from Create_Instance() method.
Here my is what if the return value of Create_Instance() is void ? Meaning if the signature is going to be "static void Create_Instance()", then how we will get the instance of Singleton in main.
Please help me in this regard.

std::map<std::string,std::string> conversion of JavaCPP

I'm a newbie of JavaCPP, right now I've got a problem.
my TestLibrary.h:
#include <string>
#include <map>
class TestClass {
public:
TestClass() {
property["a"]="b";
}
const std::map<std::string,std::string>& getMap(std::string str) {
if (str == "a"){
return property;
}
}
std::map<std::string,std::string> property;
};
TestLibrary.java
import org.bytedeco.javacpp.*;
import org.bytedeco.javacpp.annotation.*;
#Platform(include="TestLibrary.h")
public class TestLibrary {
public static class TestClass extends Pointer {
static { Loader.load(); }
public TestClass() { allocate(); }
private native void allocate();
public static native #ByRef KeyValueMap getMap(String str);
}
#Name("std::map<std::string,std::string>") public static class
KeyValueMap extends Pointer {
static { Loader.load(); }
public KeyValueMap(Pointer p) { super(p); }
public KeyValueMap() { allocate(); }
private native void allocate();
public native long size();
#Index public native #StdString BytePointer get(#StdString
BytePointer i);
public native KeyValueMap put(#StdString BytePointer i, BytePointer
value);
}
public static void main(String[] args) {
TestClass l = new TestClass();
KeyValueMap m = l.getMap("a");
System.out.println(m);
//System.out.println(m.get("a"));
}
}
when
javac -cp javacpp.jar TestLibrary.java
java -jar javacpp.jar TestLibrary
jniTestLibrary.cpp:2238:30: error: call to non-static member
function without an object argument
rptr = &::TestClass::getMap(ptr0);
~~~~~~~~~~~~~^~~~~~
the code above is modified from the NativeLibrary example. But How to solve the compile problem?
And can I use m.get("a") like that?
I managed to do this by changing...
TestLibrary.h:
#include <string>
#include <map>
class TestClass {
public:
TestClass() {
property["a"]="b";
}
std::map<std::string,std::string>& getMap(std::string str) {
if (str == "a"){
return property;
}
}
std::map<std::string,std::string> property;
};
TestLibrary.java
import org.bytedeco.javacpp.*;
import org.bytedeco.javacpp.annotation.*;
#Platform(include="TestLibrary.h")
public class TestLibrary {
public static class TestClass extends Pointer {
static { Loader.load(); }
public TestClass() { allocate(); }
private native void allocate();
public native #ByRef KeyValueMap getMap(String str);
}
#Name("std::map<std::string,std::string>")
public static class KeyValueMap extends Pointer {
static { Loader.load(); }
public KeyValueMap(Pointer p) { super(p); }
public KeyValueMap() { allocate(); }
private native void allocate();
public native long size();
#Index public native #StdString BytePointer get(#StdString BytePointer i);
public native KeyValueMap put(#StdString BytePointer i, BytePointer value); }
public static void main(String[] args) {
TestClass l = new TestClass();
KeyValueMap m = l.getMap("a");
System.out.println(m.size());
System.out.println(m.get(new BytePointer("a")).getString());
}}

Qt inherit QSpinBox and QPushButton

I would like create my CustomQSpinBox .
This CustomQSpinBox must inherit of QPushButton and QSpinBox
but when I compile this code :
#include <QSpinBox>
#include <QPushButton>
class CustomQSpinBox : public QSpinBox, public QPushButton
{
Q_OBJECT
public:
CustomQSpinBox (QWidget *parent = 0);
~CustomQSpinBox ();
void initMinMax(int min, int max);
void init();
signals:
void needNumpad();
public slots:
void clicked();
};
I get an error :
erreur : C2594: 'static_cast'ÿ: conversions ambigu‰s de 'QObject *' en
'CustomQSpinBox *'
How I must do my inheritance ?
Yes, when the numPad is closed, the value is set in the QSpinBox. The problem is so to open the numPad when I click on the QSpinBox.
For the moment I manage with this code :
#include <QSpinBox>
#include <QPushButton>
#include <QMoveEvent>
#include <QResizeEvent>
class CustomQSpinBox: public QSpinBox
{
Q_OBJECT
public:
CustomQSpinBox(QWidget *parent = 0);
~CustomQSpinBox();
void resizeEvent(QResizeEvent *event);
void moveEvent(QMoveEvent * event);
signals:
void needNumpad();
public slots:
void clicked();
private:
QPushButton * button;
};