As far as I remember -- the Project tab on left side was also ianctive during inactivity of Build-Debug menu.
But it changed to it after I closed and opened Qtcraetor -so do Qtcreator lost the configuration in such way?
And why I can delete ui, h., cpp default automatic setting - I thought it define some basic requirements for Qwidget etc...
Now again interesting problem -
after updating headers yesterday and
instantiating Lister in main():
I got such error:Qt Code:
QWidget window; window.setWindowTitle("File Indexer"); Lister f;To copy to clipboard, switch view to plain text mode
undefined reference to `Lister::Lister(QWidget*)';
when constructor is of such kind:
What the reason of it --Qt Code:
{ Q_OBJECTTo copy to clipboard, switch view to plain text mode
now all headers are included, as source files?
How define correctly, as the link provide exactly such solution despite it doesnot works here.
Last edited by artt; 17th December 2015 at 01:09.
This is the implementation of Constructor of Lister in main ():
It is almost the same as in link from java2s example:Qt Code:
QWidget window; window.setWindowTitle("File Indexer"); Lister f;To copy to clipboard, switch view to plain text mode
What definition or implementaion of Lister constructor should look like? In Lister.cpp (in my case Filewalker.cpp, despite the change of name inprobably matters)
That code does not show the implementation of the constructor of Lister.
It shows the instantiation of three objects and a method call on one of these objects.
Like any other method its signature needs to match the signature of its declaration.
What you do in the function body obviously depends on what that class needs to do in the constructor.
Cheers,
_
class Lister : public QWidget
{
Q_OBJECT
public: Lister (QWidget *parent = 0 );
is it not the same as Lister::Lister(QWidget *parent = 0) in Lister.cpp?
What is Lister (QWidget *parent = 0 )?
In the example http://www.java2s.com/Code/Cpp/Qt/extendsQWidget.htm you see the same definition of Constructor
despite with 2 arguments. But there is no Circlebar::Circlebar...in circlebar.cpp - so I cannot copy this example for that my compiler says in the last case.
Yes, you've already shown the declaration
No, that is a non-line (not in the header) definition, although it should have the "= 0" part, but the compiler will complain about that anyway.
That depends on how the code after that looks like.
If the ? is a ; then
- In a class called "Lister" this would be the declaration of a constructor.
- In a class called something else, this would be the declaration of a method.
- Outside a class that would be the declaration of a function.
If the ? is a { then
- In a class called "Lister" this would be the declaration and inline definition of a constructor.
- In a class called something else, this would be the declaration and inline definition of a method.
- Outside a class that would be the declaration and inline definition of a function.
Yes, indeed.
Yes, constructors can have any number of arguments
Of course, right there in the link you've provided, first thing after the includes.
Cheers,
_
Sorry, I automatically overlooked it as I thought it is without need.
But my lister is in fact the void class except static slot functions and static Qlist listed variable, so
I think I should probably use such examples doc.qt.io/qt-4.8/designer-using-a-ui-file.html
http://stackoverflow.com/questions/1...idget-parent-0
Despite I cannot override the inactive build-debug menu in Qtcreator...So it is difficult to check in time.
No really the java2s example is very appropriate:
It worksQt Code:
{ }To copy to clipboard, switch view to plain text mode
But now the issue is in connect statement that works for
QObject::connect(indexate, SIGNAL(clicked()),&f,SLOT(readxmlfile()));
But the next function despite finely compiled and run is not active - e.i. its button--end this connect statement is underlained by red wavy line--it was happened the several last days with red line
QObject::connect(indexate, SIGNAL(clicked()),&f,SLOT(walk("C:\\C")));
I change to another folder -the same...
Artt, I'll say it again: Clearly you do not understand enough of the basics of C++ to write the program you are trying to write. Every question you ask shows that you do not understand.
C++ is not java, even though the syntax is similar. In C++, the definition of a class is usually divided among two files: a header file, usually with a ".h" or ".hpp" suffix, and an implementation file, usually with a ".cpp" suffix. In the header file, the name of the class, its inheritance, and any member variables and functions are declared, but not very often implemented. So, in your case:
Qt Code:
{ Q_OBJECTTo copy to clipboard, switch view to plain text mode
This code "declares" that there is a class called "Lister", that it publicly "inherits" from another class called "QWidget", and "declares" that there is a constructor method ("Lister()") that takes an optional argument of type "pointer to QWidget". If the argument is not provided in the code that uses the Lister class, the compiler is told to insert a "0" (null pointer) to be used instead. The Q_OBJECT macro inserts some macro code for Qt's meta-object system which you do not need to know anything about.
This code does not implement Lister, it simply makes the declarations I have explained above. In order for the Lister class to be used in your program, you have to define the implementation of the constructor and any other methods in the cpp file:
Qt Code:
// Lister.cpp #include "Lister.h" { }To copy to clipboard, switch view to plain text mode
In addition, Lister.cpp must be compiled and linked into your program, otherwise the linker will tell you that there is an undefined reference to it. It isn't enough just to have the file laying on your disk drive. You have to add it to the project file, otherwise nothing will happen with it and you will get linker errors.
I am also convinced that you do not understand the meaning of the C++ keyword "static" when applied to methods of a class. It makes no sense at all to have a class whose methods are all declared "static" but which also contains a public constructor and non-static member variables.
So please. get yourself a C++ textbook and learn how the language works. C++ is not java, and very little of what you know about java can be applied to C++.
Should I make this methods non-static? Why? There are no non-static variable and methods in Lister, just static --despite all of them is thransfered from Filewalker - that I made - in course of events -- just for instances. In this situation I just copied the constructor infos from java2s examples no more.It makes no sense at all to have a class whose methods are all declared "static" but which also contains a public constructor and non-static member variables.
So please. get yourself a C++ textbook and learn how the language works. C++ is not java, and very little of what you know about java can be applied to C++
And I have read a lot of books - this my first big project either in C++ and Qt.
And this project works almost except I should add the Textedit for rendering xml and Qlabel for displaying the result of searchbyname.
And of course- then realize with Qthreads-- As a results it will help me very well in practical familiarization with Qt and C++.
Everything else is known for me at this moment. Yet about 10 days ago I did not used never .h
files but I know now that I could put several class headers in one .h file. But why not use public constructor if there is example in java2s and static methods I do not know - what is your idea of design?
Added after 17 minutes:
The last question was very simple - do SLOT(function("path")) do not work correctly as simmply SLOT(function()) - this is just about Qt
Last edited by artt; 18th December 2015 at 01:09.
Is "indexate" a pointer to a QObject derived class?
Does it have a clicked() signal?
Is &f a pointer to a QObject derived class?
Does it have a readxmlfile() slot?
That is not a valid SLOT macro content.
As I explained earlier, the SIGNAL and SLOT macros contain method names and, if applicable, argument types.
"C:\\C" is not a C++ type, it is a string literal.
Cheers,
_
So It should work like SLOT(walk()) but do not work like SLOT(walk("C:\C")). Is it impossible to work with last variant anyway? Should I include the dialog for choosing appropriate folder in walk()? But there is some moments when you need to use method with explicit definition of path as argument...
Yes, "..." is a string literal, not a type name.
Yes, as explained at least twice already, the SLOT macros needs a method name and, if necessary, the types of the arguments.
If that is what you want to do, why not.
Then you call the method with the path.
Really the same as in Java.
Cheers,
_
"Then you call the method with the path." - so how to call such method coorectly?
If walk("C:\C") is the string literal (or to exactly "C:\C")) - what kind of type is walk() as it is method with void return type.
You are mixing things up.
Calling
is fine.
Just putting that into a SLOT macro is not since that requires a slot signature.
Cheers,
_
Should I put in such manner -
QObject::connect(indexate, SIGNAL(clicked()),&f,walk("C:\\C"))?
Bookmarks