A simple int-type global variable is described earlier, but for a more complex vector type, the above method can be used for reference, but the problem of initialization should be different.
Global variables: Declared in the class of the header file, initialized outside the function body of the CPP file. This is the basic routine.
The static variables of the class must be initialized outside of the class, you know.
A little more specific.
STLView.h
class Stlview {public:stlview (); Declares the constructor bool Readstl (const QString &fname); Read STL data qvector<mytriangle> Trianglevector; Set of triangular polygons static int splitstring (const QString &str, Char split, qvector<qstring>& Strarray); is a static member function double trianglezmax,trianglezmin;
Defines the z-coordinate maximum and minimum values for all triangular patches static bool Comp (const mytriangle &a, const mytriangle &b); Sorting functions, sorted by mytriangle.zmin values; the larger the qvector ordinal, the larger the zmin, the higher the ascending order, the static member function that must be written here//if the zmin of triangles A and B are the same, then the order of A and B in the STL file, in front of it,
Finally in the qvector inside row behind//double read (); MyPoint Linedir,testpoint; Define the direction of the two-point line, test point qvector<crosspoint> crosspointvector; Intersection container static qvector<qpointf> vector;
Set the contour two-dimensional point information, define a vector to store qpoint type of point static qpointf points; static int A; Define global variables double zlevel; Defines the value of the Z-plane double Dist (mypoint P1, MyPoint P2); Calculate two points away from bool between (MyPoint P1, MyPoint P2, MyPoint P3);
Determine if the point3 is between Point1 and Point2};
STLView.cpp
#include "STLView.h"
#include <QFile>
#include <QTextStream>
#include <QDebug>
# Include <qtalgorithms>//data sorting
#include <QList>
int stlview::a = 11111;//int type initialization
qpointf Stlview::p oint = qpointf (); Vector type initialization
qvector<qpointf> stlview::vector = qvector<qpointf> ();
Stlview::stlview ()//default constructor, declaration with array must have default constructor
{
}
One problem has to be taken seriously:
When assigning the initial value to a vector of the qpointf type, the general vector assignment is append,push_back, but the two functions must be used inside the function;
External to the global variable vector assignment, obviously append,push_back is not useful, so we call the vector's constructor, and then in the class's constructor insert or assign a value.
Finally, thank you Dalian (27754587) Brother Wei