Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
Quote:
Originally Posted by
artt
So why build-debug menu is inactive?
Maybe the project is not configured?
See the project button on the left hand side.
Quote:
Originally Posted by
artt
Can I also delete filewalker2.ui form file?
If it is not used, sure.
Cheers,
_
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
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...
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
Quote:
Originally Posted by
artt
And why I can delete ui, h., cpp default automatic setting - I thought it define some basic requirements for Qwidget etc...
For someone who claims to have been developing software before, in any language, that is a pretty strange question.
A file not being used is a file not needed.
Cheers,
_
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
Now again interesting problem -
after updating headers yesterday and
instantiating Lister in main():
Code:
window.setWindowTitle("File Indexer");
Lister f;
I got such error:
undefined reference to `Lister::Lister(QWidget*)';
when constructor is of such kind:
Code:
{
Q_OBJECT
public: Lister
(QWidget *parent
= 0 );
What the reason of it --
now all headers are included, as source files?
How define correctly, as the link provide exactly such solution despite it doesnot works here.
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
Quote:
Originally Posted by
artt
I got such error:
undefined reference to `Lister::Lister(QWidget*)';
when constructor is of such kind:
Code:
{
Q_OBJECT
public: Lister
(QWidget *parent
= 0 );
What the reason of it --
Do you have the constructors definition/implementation somewhere?
E.g. in the lister source file?
Cheers,
_
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
This is the implementation of Constructor of Lister in main ():
Code:
window.setWindowTitle("File Indexer");
Lister f;
It is almost the same as in link from java2s example:
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)
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
Quote:
Originally Posted by
artt
This is the implementation of Constructor of Lister in main ():
Code:
window.setWindowTitle("File Indexer");
Lister f;
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.
Quote:
Originally Posted by
artt
What definition or implementaion of Lister constructor should look like?
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,
_
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
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.
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
Quote:
Originally Posted by
artt
Code:
{
Q_OBJECT
public: Lister
(QWidget *parent
= 0 );
Yes, you've already shown the declaration
Quote:
Originally Posted by
artt
is it not the same as Lister::Lister(QWidget *parent = 0) in Lister.cpp?
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.
Quote:
Originally Posted by
artt
What is Lister (QWidget *parent = 0 )?
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.
Quote:
Originally Posted by
artt
Yes, indeed.
Quote:
Originally Posted by
artt
despite with 2 arguments.
Yes, constructors can have any number of arguments
Quote:
Originally Posted by
artt
But there is no Circlebar::Circlebar...in circlebar.cpp
Of course, right there in the link you've provided, first thing after the includes.
Cheers,
_
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
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.
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
Quote:
Originally Posted by
artt
But my lister is in fact the void class except static slot functions and static Qlist listed variable, so
Then you don't need a constructor.
But I thought you wanted slots in that class?
Quote:
Originally Posted by
artt
I think I should probably use such examples doc.qt.io/qt-4.8/designer-using-a-ui-file.html
How is this relevant here?
Cheers,
_
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
No really the java2s example is very appropriate:
It works
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...
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
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:
Code:
{
Q_OBJECT
public: Lister
(QWidget *parent
= 0 );
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:
Code:
// Lister.cpp
#include "Lister.h"
{
}
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++.
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
Quote:
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.
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
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
Quote:
Originally Posted by
artt
But now the issue is in connect statement that works for
QObject::connect(indexate, SIGNAL(clicked()),&f,SLOT(readxmlfile()));
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?
Quote:
Originally Posted by
artt
QObject::connect(indexate, SIGNAL(clicked()),&f,SLOT(walk("C:\\C")));
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,
_
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
Quote:
Originally Posted by
anda_skoa
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...
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
Quote:
Originally Posted by
artt
So It should work like SLOT(walk()) but do not work like SLOT(walk("C:\C")).
Yes, "..." is a string literal, not a type name.
Quote:
Originally Posted by
artt
Is it impossible to work with last variant anyway?
Yes, as explained at least twice already, the SLOT macros needs a method name and, if necessary, the types of the arguments.
Quote:
Originally Posted by
artt
Should I include the dialog for choosing appropriate folder in walk()?
If that is what you want to do, why not.
Quote:
Originally Posted by
artt
But there is some moments when you need to use method with explicit definition of path as argument...
Then you call the method with the path.
Really the same as in Java.
Cheers,
_
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
"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.
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
Quote:
Originally Posted by
artt
"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,
_
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
Should I put in such manner -
QObject::connect(indexate, SIGNAL(clicked()),&f,walk("C:\\C"))?